Skip to content

Commit a5bc9d1

Browse files
udpating read me
1 parent 7a6d867 commit a5bc9d1

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ An open-source Swift package designed for effortless interaction with OpenAI's p
1717
- [Usage](#usage)
1818
- [Azure OpenAI](#azure-openai)
1919
- [AIProxy](#aiproxy)
20+
- [Ollama](#ollama)
2021
- [Collaboration](#collaboration)
2122

2223
## Description
@@ -3066,5 +3067,46 @@ Contributors of this library provide third party integrations as a convenience.
30663067
party's services are assumed at your own risk.
30673068

30683069

3070+
## Ollama
3071+
3072+
Ollama now has built-in compatibility with the OpenAI [Chat Completions API](https://github.com/ollama/ollama/blob/main/docs/openai.md), making it possible to use more tooling and applications with Ollama locally.
3073+
3074+
<img width="783" alt="Screenshot 2024-06-24 at 11 52 35 PM" src="https://github.com/jamesrochabrun/SwiftOpenAI/assets/5378604/db2264cb-408c-471d-b65b-912795c082ed">
3075+
3076+
### ⚠️ Important
3077+
3078+
Remember that these models run locally, so you need to download them. If you want to use llama3, you can open the terminal and run the following command:
3079+
3080+
```python
3081+
ollama pull llama3
3082+
```
3083+
3084+
you can follow [Ollama documentation](https://github.com/ollama/ollama/blob/main/docs/openai.md) for more.
3085+
3086+
### How to use this models locally using SwiftOpenAI?
3087+
3088+
To use local models with an `OpenAIService` in your application, you need to provide a URL.
3089+
3090+
```swift
3091+
let service = OpenAIServiceFactory.ollama(baseURL: "http://localhost:11434")
3092+
```
3093+
3094+
Then you can use the completions API as follows:
3095+
3096+
```swift
3097+
let prompt = "Tell me a joke"
3098+
let parameters = ChatCompletionParameters(messages: [.init(role: .user, content: .text(prompt))], model: .custom("llama3"))
3099+
let chatCompletionObject = service.startStreamedChat(parameters: parameters)
3100+
```
3101+
3102+
### Resources:
3103+
3104+
[Ollama OpenAI compatibility docs.](https://github.com/ollama/ollama/blob/main/docs/openai.md)
3105+
[Ollama OpenAI compatibility blog post.](https://ollama.com/blog/openai-compatibility)
3106+
3107+
3108+
30693109
## Collaboration
30703110
Open a PR for any proposed change pointing it to `main` branch. Unit tests are highly appreciated ❤️
3111+
3112+

0 commit comments

Comments
 (0)