https://github.com/0xopenbytes/chatservice
🤖 Chat with GPT
https://github.com/0xopenbytes/chatservice
async async-await chat chatgpt gpt ios macos network openai swift swiftui tvos watchos
Last synced: 11 days ago
JSON representation
🤖 Chat with GPT
- Host: GitHub
- URL: https://github.com/0xopenbytes/chatservice
- Owner: 0xOpenBytes
- License: mit
- Created: 2023-03-09T23:50:40.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2023-03-10T00:29:23.000Z (about 2 years ago)
- Last Synced: 2025-03-29T04:25:39.353Z (29 days ago)
- Topics: async, async-await, chat, chatgpt, gpt, ios, macos, network, openai, swift, swiftui, tvos, watchos
- Language: Swift
- Homepage: https://0xopenbytes.github.io/ChatService/
- Size: 8.79 KB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ChatService
*🤖 Chat with GPT*
ChatService is a Swift package that provides a simple API for chatting with an AI-powered bot based on GPT (Generative Pretrained Transformer) architecture. The package uses OpenAI's GPT models to generate responses to user inputs.
**[OpenAI API Reference](https://platform.openai.com/docs/api-reference/chat)**
## Usage
To use ChatService in your app, first import the module:
```swift
import ChatService
```Then, create an instance of ChatService with your OpenAI API key:
```swift
let chatService = ChatService(key: "YOUR_OPENAI_API_KEY")
```You can then use the completion method to generate a response to a user message:
```swift
let response: String = try await chatService.completion(for: "Hello?")
```You can access the chat history using the chatHistory property of the ChatService object:
```swift
let chatHistory: [ChatService.Chat] = chat.chatHistory
```