Skip to content

Commit

Permalink
Merge pull request #216 from miurla/fix-ollama
Browse files Browse the repository at this point in the history
Fix environment variable handling and Update README
  • Loading branch information
miurla authored Jun 9, 2024
2 parents 74868c9 + 97bbb82 commit c7bb526
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .env.local.example
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ UPSTASH_REDIS_REST_TOKEN=[YOUR_UPSTASH_REDIS_REST_TOKEN]
# Google Generative AI API key retrieved here: https://aistudio.google.com/app/apikey
# GOOGLE_GENERATIVE_AI_API_KEY=[YOUR_GOOGLE_GENERATIVE_AI_API_KEY]

# If you want to use Ollama, enable the following variables.
# [Unstable] If you want to use Ollama, enable the following variables.
# OLLAMA_MODEL=[YOUR_OLLAMA_MODEL] # The main model to use. Recommended: mistral or openherms
# OLLAMA_SUB_MODEL=[YOUR_OLLAMA_SUB_MODEL] # The sub model to use. Recommended: phi3 or llama3
# OLLAMA_BASE_URL=[YOUR_OLLAMA_URL] # The base URL to use. e.g. http://localhost:11434
Expand Down
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Please note that there are differences between this repository and the official
- [x] Add video support for search functionality
- [x] Support Google Generative AI Provider ([](https://github.com/miurla/morphic/issues/192))
- [x] [Use as a search engine](#-search-engine)
- [x] Unstable: Support Ollama Provider ([](https://github.com/miurla/morphic/issues/215))

## 🧱 Stack

Expand Down Expand Up @@ -130,16 +131,18 @@ This will allow you to use Morphic as your default search engine in the browser.

## ✅ Verified models

List of models applicable to all:
### List of models applicable to all:

- OpenAI
- gpt-4o
- gpt-4-turbo
- gpt-3.5-turbo
- Google
- Gemini 1.5 pro [](https://github.com/miurla/morphic/issues/192)
- Ollama (Unstable)
- mistral/openherms & Phi3/llama3 [](https://github.com/miurla/morphic/issues/215)

List of verified models that can be specified to writers:
### List of verified models that can be specified to writers:

- [Groq](https://console.groq.com/docs/models)
- LLaMA3 8b
Expand Down
13 changes: 7 additions & 6 deletions lib/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ export function getModel(useSubModel = false) {
const openaiApiBase = process.env.OPENAI_API_BASE
const openaiApiKey = process.env.OPENAI_API_KEY
let openaiApiModel = process.env.OPENAI_API_MODEL || 'gpt-4o'
const googleApiKey = process.env.GOOGLE_GENERATIVE_AI_API_KEY

if (!(ollamaBaseUrl && ollamaModel) && !(openaiApiBase && openaiApiKey)) {
throw new Error('Missing environment variables for Ollama and OpenAI')
if (!(ollamaBaseUrl && ollamaModel) && !openaiApiKey && !googleApiKey) {
throw new Error(
'Missing environment variables for Ollama, OpenAI, or Google'
)
}

// Ollama

if (ollamaBaseUrl && ollamaModel) {
const ollama = createOllama({ baseURL: ollamaBaseUrl })

Expand All @@ -40,8 +41,8 @@ export function getModel(useSubModel = false) {
// Fallback to OpenAI instead

const openai = createOpenAI({
baseUrl: process.env.OPENAI_API_BASE, // optional base URL for proxies etc.
apiKey: process.env.OPENAI_API_KEY, // optional API key, default to env property OPENAI_API_KEY
baseUrl: openaiApiBase, // optional base URL for proxies etc.
apiKey: openaiApiKey, // optional API key, default to env property OPENAI_API_KEY
organization: '' // optional organization
})

Expand Down

0 comments on commit c7bb526

Please sign in to comment.