-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
693 additions
and
390 deletions.
There are no files selected for viewing
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
export interface CohereModelOptions { | ||
apiKey: string; | ||
modelId: string; | ||
/** | ||
* If the AudioPart has a transcript, convert it to an TextPart | ||
*/ | ||
convertAudioPartsToTextParts?: boolean; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,67 @@ | ||
/* eslint-disable @typescript-eslint/no-floating-promises */ | ||
import { describe, it } from "node:test"; | ||
import test, { suite } from "node:test"; | ||
import { AnthropicModel } from "../src/anthropic/anthropic.js"; | ||
import { getLanguageModelTests } from "./test-language-model.js"; | ||
import { log, testLanguageModel } from "./test-language-model.js"; | ||
|
||
const model = new AnthropicModel({ | ||
apiKey: process.env["ANTHROPIC_API_KEY"] as string, | ||
modelId: "claude-3-5-sonnet-20241022", | ||
}); | ||
const model = new AnthropicModel( | ||
{ | ||
apiKey: process.env["ANTHROPIC_API_KEY"] as string, | ||
modelId: "claude-3-5-sonnet-20241022", | ||
}, | ||
{ | ||
pricing: { | ||
inputCostPerTextToken: 3.0 / 1_000_000, | ||
outputCostPerTextToken: 15.0 / 1_000_000, | ||
}, | ||
}, | ||
); | ||
|
||
suite("AnthropicModel", () => { | ||
testLanguageModel(model); | ||
|
||
test("convert audio part to text part if enabled", async () => { | ||
const model = new AnthropicModel({ | ||
apiKey: process.env["ANTHROPIC_API_KEY"] as string, | ||
// not an audio model | ||
modelId: "claude-3-5-sonnet-20241022", | ||
convertAudioPartsToTextParts: true, | ||
}); | ||
|
||
const response = await model.generate({ | ||
messages: [ | ||
{ | ||
role: "user", | ||
content: [ | ||
{ | ||
type: "text", | ||
text: "Hello", | ||
}, | ||
], | ||
}, | ||
{ | ||
role: "assistant", | ||
content: [ | ||
{ | ||
type: "audio", | ||
audioData: "", | ||
transcript: "Hi there, how can I help you?", | ||
}, | ||
], | ||
}, | ||
{ | ||
role: "user", | ||
content: [ | ||
{ | ||
type: "text", | ||
text: "Goodbye", | ||
}, | ||
], | ||
}, | ||
], | ||
}); | ||
|
||
log(response); | ||
|
||
describe("AnthropicModel", () => { | ||
const tests = getLanguageModelTests(model); | ||
tests.forEach(({ name, fn }) => { | ||
it(name, fn); | ||
// it should not throw a part unsupported error | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1,16 +1,67 @@ | ||
/* eslint-disable @typescript-eslint/no-floating-promises */ | ||
import { describe, it } from "node:test"; | ||
import test, { suite } from "node:test"; | ||
import { CohereModel } from "../src/cohere/cohere.js"; | ||
import { getLanguageModelTests } from "./test-language-model.js"; | ||
import { log, testLanguageModel } from "./test-language-model.js"; | ||
|
||
const model = new CohereModel({ | ||
apiKey: process.env["CO_API_KEY"] as string, | ||
modelId: "command-r-08-2024", | ||
}); | ||
const model = new CohereModel( | ||
{ | ||
apiKey: process.env["CO_API_KEY"] as string, | ||
modelId: "command-r-08-2024", | ||
}, | ||
{ | ||
pricing: { | ||
inputCostPerTextToken: 0.16 / 1_000_000, | ||
outputCostPerTextToken: 0.6 / 1_000_000, | ||
}, | ||
}, | ||
); | ||
|
||
suite("CohereModel", () => { | ||
testLanguageModel(model); | ||
|
||
test("convert audio part to text part if enabled", async () => { | ||
const model = new CohereModel({ | ||
apiKey: process.env["CO_API_KEY"] as string, | ||
// not an audio model | ||
modelId: "command-r-08-2024", | ||
convertAudioPartsToTextParts: true, | ||
}); | ||
|
||
const response = await model.generate({ | ||
messages: [ | ||
{ | ||
role: "user", | ||
content: [ | ||
{ | ||
type: "text", | ||
text: "Hello", | ||
}, | ||
], | ||
}, | ||
{ | ||
role: "assistant", | ||
content: [ | ||
{ | ||
type: "audio", | ||
audioData: "", | ||
transcript: "Hi there, how can I help you?", | ||
}, | ||
], | ||
}, | ||
{ | ||
role: "user", | ||
content: [ | ||
{ | ||
type: "text", | ||
text: "Goodbye", | ||
}, | ||
], | ||
}, | ||
], | ||
}); | ||
|
||
log(response); | ||
|
||
describe("CohereModel", () => { | ||
const tests = getLanguageModelTests(model); | ||
tests.forEach(({ name, fn }) => { | ||
it(name, fn); | ||
// it should not throw a part unsupported error | ||
}); | ||
}); |
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,67 @@ | ||
/* eslint-disable @typescript-eslint/no-floating-promises */ | ||
import test, { suite } from "node:test"; | ||
import { GoogleModel } from "../src/google/google.js"; | ||
import { log, testLanguageModel } from "./test-language-model.js"; | ||
|
||
const model = new GoogleModel( | ||
{ | ||
apiKey: process.env["GOOGLE_API_KEY"] as string, | ||
modelId: "gemini-1.5-pro", | ||
}, | ||
{ | ||
pricing: { | ||
inputCostPerTextToken: 1.25 / 1_000_000, | ||
outputCostPerTextToken: 5.0 / 1_000_000, | ||
}, | ||
}, | ||
); | ||
|
||
suite("GoogleModel", () => { | ||
testLanguageModel(model); | ||
|
||
test("convert audio part to text part if enabled", async () => { | ||
const model = new GoogleModel({ | ||
apiKey: process.env["GOOGLE_API_KEY"] as string, | ||
// not an audio model | ||
modelId: "gemini-1.5-pro", | ||
convertAudioPartsToTextParts: true, | ||
}); | ||
|
||
const response = await model.generate({ | ||
messages: [ | ||
{ | ||
role: "user", | ||
content: [ | ||
{ | ||
type: "text", | ||
text: "Hello", | ||
}, | ||
], | ||
}, | ||
{ | ||
role: "assistant", | ||
content: [ | ||
{ | ||
type: "audio", | ||
audioData: "", | ||
transcript: "Hi there, how can I help you?", | ||
}, | ||
], | ||
}, | ||
{ | ||
role: "user", | ||
content: [ | ||
{ | ||
type: "text", | ||
text: "Goodbye", | ||
}, | ||
], | ||
}, | ||
], | ||
}); | ||
|
||
log(response); | ||
|
||
// it should not throw a part unsupported error | ||
}); | ||
}); |
Oops, something went wrong.