Skip to content

Commit

Permalink
change SDK
Browse files Browse the repository at this point in the history
use "@fuyun/generative-ai": "0.1.1" isstead , support baseurl
  • Loading branch information
babaohuang committed Dec 17, 2023
1 parent 5fbfb89 commit db085e8
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ GEMINI_API_KEY=
# Provide proxy for OpenAI API. e.g. http://127.0.0.1:7890
HTTPS_PROXY=
# Custom base url for OpenAI API. default: https://api.openai.com
OPENAI_API_BASE_URL=
API_BASE_URL=
# Inject analytics or other scripts before </head> of the page
HEAD_SCRIPTS=
# Secret string for the project. Use for generating signatures for API calls
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"@astrojs/node": "^5.3.0",
"@astrojs/solid-js": "^2.2.0",
"@astrojs/vercel": "^3.5.0",
"@google/generative-ai": "^0.1.1",
"@fuyun/generative-ai": "0.1.1",
"@zag-js/slider": "^0.16.0",
"@zag-js/solid": "^0.16.0",
"astro": "^2.7.0",
Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 7 additions & 3 deletions src/utils/openAI.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { GoogleGenerativeAI } from '@google/generative-ai'
import { GoogleGenerativeAI } from '@fuyun/generative-ai'

const apiKey = process.env.GEMINI_API_KEY
const genAI = new GoogleGenerativeAI(apiKey)
const apiBaseUrl = process.env.API_BASE_URL

const genAI = apiBaseUrl
? new GoogleGenerativeAI(apiKey, apiBaseUrl)
: new GoogleGenerativeAI(apiKey)

export const startChatAndSendMessageStream = async(history: ChatMessage[], newMessage: string) => {
const model = genAI.getGenerativeModel({ model: 'gemini-pro' })
Expand All @@ -19,4 +23,4 @@ export const startChatAndSendMessageStream = async(history: ChatMessage[], newMe
// Use sendMessageStream for streaming responses
const result = await chat.sendMessageStream(newMessage)
return result.stream
}
}

0 comments on commit db085e8

Please sign in to comment.