-
-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: ollama support * fix warnings and batch summarize * non null llm config * update bun lock
- Loading branch information
1 parent
f084761
commit eedfbfd
Showing
12 changed files
with
266 additions
and
129 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,6 +60,9 @@ | |
"allow": [ | ||
{ | ||
"url": "https://*.anthropic.*" | ||
}, | ||
{ | ||
"url": "http://localhost:11434" | ||
} | ||
] | ||
}, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { fetch } from '@tauri-apps/plugin-http' | ||
import { Llm, LlmConfig } from './index' | ||
|
||
export function deafultConfig(): LlmConfig { | ||
return { | ||
claudeApiKey: '', | ||
model: 'claude-3-5-sonnet-20240620', | ||
maxTokens: 8192, | ||
enabled: false, | ||
ollamaBaseUrl: '', | ||
platform: 'claude', | ||
prompt: `Please summarize the following transcription: \n\n"""\n%s\n"""\n`, | ||
} | ||
} | ||
|
||
export class Claude implements Llm { | ||
private config: LlmConfig | ||
|
||
constructor(config: LlmConfig) { | ||
this.config = config | ||
} | ||
|
||
async ask(prompt: string): Promise<string> { | ||
const body = JSON.stringify({ | ||
model: this.config.model, | ||
max_tokens: this.config.maxTokens, | ||
messages: [{ role: 'user', content: prompt }], | ||
}) | ||
const headers = { | ||
'X-API-Key': this.config.claudeApiKey, | ||
'anthropic-version': '2023-06-01', | ||
'Content-Type': 'application/json', | ||
} | ||
const response = await fetch('https://api.anthropic.com/v1/messages', { | ||
method: 'POST', | ||
headers, | ||
body, | ||
}) | ||
|
||
if (!response.ok) { | ||
console.error(`request details: `, body, headers) | ||
throw new Error(`Error: ${response.status} - ${response.statusText}`) | ||
} | ||
|
||
const data = await response.json() | ||
return data.content?.[0].text | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { Claude, deafultConfig as defaultClaudeConfig } from './claude' | ||
import { Ollama, defaultConfig as defaultOllamaConfig } from './ollama' | ||
|
||
export interface Llm { | ||
ask(prompt: string): Promise<string> | ||
} | ||
|
||
export interface LlmConfig { | ||
platform: 'ollama' | 'claude' | ||
enabled: boolean | ||
prompt: string | ||
|
||
// Claude | ||
claudeApiKey: string | ||
model: string | ||
maxTokens?: number | ||
|
||
// Ollama | ||
ollamaBaseUrl: string | ||
} | ||
|
||
export { Ollama, Claude, defaultClaudeConfig, defaultOllamaConfig } |
Oops, something went wrong.