Skip to content

Nate/fix-openai-adapters #5612

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"@continuedev/config-yaml": "file:../packages/config-yaml",
"@continuedev/fetch": "^1.0.6",
"@continuedev/llm-info": "^1.0.8",
"@continuedev/openai-adapters": "^1.0.19",
"@continuedev/openai-adapters": "^1.0.22",
"@modelcontextprotocol/sdk": "^1.5.0",
"@mozilla/readability": "^0.5.0",
"@octokit/rest": "^20.1.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/openai-adapters/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@continuedev/openai-adapters",
"version": "1.0.21",
"version": "1.0.24",
"description": "",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
5 changes: 3 additions & 2 deletions packages/openai-adapters/src/apis/DeepSeek.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,21 @@ import { chatChunk, customFetch } from "../util.js";
import { OpenAIApi } from "./OpenAI.js";
import { FimCreateParamsStreaming } from "./base.js";

export const DEEPSEEK_API_BASE = "https://api.deepseek.com/";
export class DeepSeekApi extends OpenAIApi {
apiBase: string = "https://api.deepseek.com/";
constructor(config: DeepseekConfig) {
super({
...config,
provider: "openai",
apiBase: config.apiBase ?? DEEPSEEK_API_BASE,
});
}

async *fimStream(
body: FimCreateParamsStreaming,
signal: AbortSignal,
): AsyncGenerator<ChatCompletionChunk, any, unknown> {
const endpoint = new URL("beta/completions", this.apiBase);
const endpoint = new URL("beta/completions", this.config.apiBase);
const resp = await customFetch(this.config.requestOptions)(endpoint, {
method: "POST",
body: JSON.stringify({
Expand Down
5 changes: 3 additions & 2 deletions packages/openai-adapters/src/apis/Inception.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,21 @@ import { chatChunk, customFetch } from "../util.js";
import { OpenAIApi } from "./OpenAI.js";
import { FimCreateParamsStreaming } from "./base.js";

export const INCEPTION_API_BASE = "https://api.inceptionlabs.ai/v1/";
export class InceptionApi extends OpenAIApi {
apiBase: string = "https://api.inceptionlabs.ai/v1/";
constructor(config: InceptionConfig) {
super({
...config,
provider: "openai",
apiBase: config.apiBase ?? INCEPTION_API_BASE,
});
}

async *fimStream(
body: FimCreateParamsStreaming,
signal: AbortSignal,
): AsyncGenerator<ChatCompletionChunk, any, unknown> {
const endpoint = new URL("completions", this.apiBase);
const endpoint = new URL("completions", this.config.apiBase);
const resp = await customFetch(this.config.requestOptions)(endpoint, {
method: "POST",
body: JSON.stringify({
Expand Down
44 changes: 44 additions & 0 deletions packages/openai-adapters/src/test/main.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { ModelConfig } from "@continuedev/config-yaml";
import * as dotenv from "dotenv";
import { DEEPSEEK_API_BASE } from "../apis/DeepSeek.js";
import { INCEPTION_API_BASE } from "../apis/Inception.js";
import { OpenAIApi } from "../apis/OpenAI.js";
import { constructLlmApi } from "../index.js";
import { getLlmApi, testChat, testCompletion, testEmbed } from "./util.js";

dotenv.config();
Expand Down Expand Up @@ -108,3 +112,43 @@ TESTS.forEach((config) => {
testConfig({ name: config.model, ...config });
});
});

describe("Configuration", () => {
it("should configure DeepSeek OpenAI client with correct apiBase and apiKey", () => {
const deepseek = constructLlmApi({
provider: "deepseek",
apiKey: "sk-xxx",
});

expect((deepseek as OpenAIApi).openai.baseURL).toBe(DEEPSEEK_API_BASE);
expect((deepseek as OpenAIApi).openai.apiKey).toBe("sk-xxx");

const deepseek2 = constructLlmApi({
provider: "deepseek",
apiKey: "sk-xxx",
apiBase: "https://api.example.com",
});
expect((deepseek2 as OpenAIApi).openai.baseURL).toBe(
"https://api.example.com",
);
});

it("should configure Inception OpenAI client with correct apiBase and apiKey", () => {
const inception = constructLlmApi({
provider: "inception",
apiKey: "sk-xxx",
});

expect((inception as OpenAIApi).openai.baseURL).toBe(INCEPTION_API_BASE);
expect((inception as OpenAIApi).openai.apiKey).toBe("sk-xxx");

const inception2 = constructLlmApi({
provider: "inception",
apiKey: "sk-xxx",
apiBase: "https://api.example.com",
});
expect((inception2 as OpenAIApi).openai.baseURL).toBe(
"https://api.example.com",
);
});
});
Loading