-
Notifications
You must be signed in to change notification settings - Fork 0
Add new llm providers for users #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,68 @@ | ||||||||||||||||||||||||||||
| const OpenAI = require('openai') | ||||||||||||||||||||||||||||
| const Anthropic = require('@anthropic-ai/sdk') | ||||||||||||||||||||||||||||
| const cohere = require('cohere-ai') | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| const providers = { | ||||||||||||||||||||||||||||
| openai: { | ||||||||||||||||||||||||||||
| name: 'OpenAI', | ||||||||||||||||||||||||||||
| client: new OpenAI({ | ||||||||||||||||||||||||||||
| apiKey: process.env.OPENAI_API_KEY | ||||||||||||||||||||||||||||
| }), | ||||||||||||||||||||||||||||
| models: ['gpt-3.5-turbo', 'gpt-4'], | ||||||||||||||||||||||||||||
| generate: async (client, model, prompt) => { | ||||||||||||||||||||||||||||
| const completion = await client.chat.completions.create({ | ||||||||||||||||||||||||||||
| model, | ||||||||||||||||||||||||||||
| messages: [ | ||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||
| role: "system", | ||||||||||||||||||||||||||||
| content: "You are a helpful assistant that generates short, informative articles." | ||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||
| role: "user", | ||||||||||||||||||||||||||||
| content: prompt | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| ], | ||||||||||||||||||||||||||||
| temperature: 0.7, | ||||||||||||||||||||||||||||
| max_tokens: 500 | ||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||
| return completion.choices[0].message.content | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||
| anthropic: { | ||||||||||||||||||||||||||||
| name: 'Anthropic', | ||||||||||||||||||||||||||||
| client: new Anthropic({ | ||||||||||||||||||||||||||||
| apiKey: process.env.ANTHROPIC_API_KEY | ||||||||||||||||||||||||||||
| }), | ||||||||||||||||||||||||||||
| models: ['claude-2', 'claude-instant-1'], | ||||||||||||||||||||||||||||
| generate: async (client, model, prompt) => { | ||||||||||||||||||||||||||||
| const completion = await client.messages.create({ | ||||||||||||||||||||||||||||
| model, | ||||||||||||||||||||||||||||
| max_tokens: 500, | ||||||||||||||||||||||||||||
| messages: [ | ||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||
| role: "user", | ||||||||||||||||||||||||||||
| content: prompt | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||
|
Comment on lines
+38
to
+47
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. style: Anthropic's API requires a 'system' message and temperature parameter for consistent behavior with other providers |
||||||||||||||||||||||||||||
| return completion.content[0].text | ||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. logic: Accessing completion.content[0].text is incorrect for Anthropic's API - should be completion.content
Suggested change
|
||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||
| cohere: { | ||||||||||||||||||||||||||||
| name: 'Cohere', | ||||||||||||||||||||||||||||
| client: cohere, | ||||||||||||||||||||||||||||
| models: ['command', 'command-light'], | ||||||||||||||||||||||||||||
| generate: async (client, model, prompt) => { | ||||||||||||||||||||||||||||
| client.init(process.env.COHERE_API_KEY) | ||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. style: Cohere client initialization should be moved outside the generate function to avoid reinitializing on every call
Suggested change
|
||||||||||||||||||||||||||||
| const response = await client.generate({ | ||||||||||||||||||||||||||||
| model, | ||||||||||||||||||||||||||||
| prompt, | ||||||||||||||||||||||||||||
| max_tokens: 500, | ||||||||||||||||||||||||||||
| temperature: 0.7 | ||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||
|
Comment on lines
+57
to
+62
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. logic: Cohere's generate API requires a 'num_generations' parameter, otherwise it may return empty results
Suggested change
|
||||||||||||||||||||||||||||
| return response.body.generations[0].text | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| module.exports = providers | ||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: Path './src/llm/providers' doesn't match actual file location './src/llms/providers'