Skip to content

Commit

Permalink
Merge pull request #82 from Nil2000/main
Browse files Browse the repository at this point in the history
Follow up to the previous PR "✔️ Anthropic model added"
  • Loading branch information
miurla authored Apr 25, 2024
2 parents 9560987 + ac27c5e commit 3296aab
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .env.local.example
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ TAVILY_API_KEY=

# Only writers can set a specific model. It must be compatible with the OpenAI API.
# USE_SPECIFIC_API_FOR_WRITER=true
# Mention specific provider below("anthorpic" or "openai")
# SPECIFIC_PROVIDER=
# SPECIFIC_API_BASE=
# SPECIFIC_API_KEY=
# SPECIFIC_API_MODEL=
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ TAVILY_API_KEY=[YOUR_TAVILY_API_KEY]
# Only writers can set a specific model. It must be compatible with the OpenAI API.
# USE_SPECIFIC_API_FOR_WRITER=true
# Mention specific provider below("anthorpic" or "openai")
# SPECIFIC_PROVIDER=
# SPECIFIC_API_BASE=
# SPECIFIC_API_KEY=
# SPECIFIC_API_MODEL=
Expand Down
Binary file modified bun.lockb
Binary file not shown.
25 changes: 17 additions & 8 deletions lib/agents/writer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,25 @@ import { createStreamableUI, createStreamableValue } from 'ai/rsc'
import { ExperimentalMessage, experimental_streamText } from 'ai'
import { Section } from '@/components/section'
import { BotMessage } from '@/components/message'

import { createAnthropic } from '@ai-sdk/anthropic';
export async function writer(
uiStream: ReturnType<typeof createStreamableUI>,
streamText: ReturnType<typeof createStreamableValue<string>>,
messages: ExperimentalMessage[]
) {
const openai = new OpenAI({
baseUrl: process.env.SPECIFIC_API_BASE,
apiKey: process.env.SPECIFIC_API_KEY,
organization: '' // optional organization
})

var openai, anthropic;
if (process.env.SPECIFIC_PROVIDER === 'anthropic') {
anthropic = createAnthropic({
baseUrl: process.env.SPECIFIC_API_BASE,
apiKey: process.env.SPECIFIC_API_KEY,
})
} else {
openai = new OpenAI({
baseUrl: process.env.SPECIFIC_API_BASE,
apiKey: process.env.SPECIFIC_API_KEY,
organization: '' // optional organization
})
}
let fullResponse = ''
const answerSection = (
<Section title="Answer">
Expand All @@ -24,7 +31,9 @@ export async function writer(
uiStream.append(answerSection)

await experimental_streamText({
model: openai.chat(process.env.SPECIFIC_API_MODEL || 'llama3-70b-8192'),
model: process.env.SPECIFIC_PROVIDER === 'anthropic' ?
anthropic!(process.env.SPECIFIC_API_MODEL || 'claude-3-haiku-20240307') :
openai!.chat(process.env.SPECIFIC_API_MODEL || 'llama3-70b-8192'),
maxTokens: 2500,
system: `As a professional writer, your job is to generate a comprehensive and informative, yet concise answer of 400 words or less for the given question based solely on the provided search results (URL and content). You must only use information from the provided search results. Use an unbiased and journalistic tone. Combine search results together into a coherent answer. Do not repeat text. If there are any images relevant to your answer, be sure to include them as well. Aim to directly address the user's question, augmenting your response with insights gleaned from the search results.
Whenever quoting or referencing information from a specific URL, always cite the source URL explicitly. Please match the language of the response to the user's language.
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"lint": "next lint"
},
"dependencies": {
"@ai-sdk/anthropic": "^0.0.7",
"@ai-sdk/openai": "^0.0.2",
"@radix-ui/react-avatar": "^1.0.4",
"@radix-ui/react-checkbox": "^1.0.4",
Expand Down

0 comments on commit 3296aab

Please sign in to comment.