Skip to content

Commit

Permalink
Merge pull request #1 from janhq/chore/add-start-model-api
Browse files Browse the repository at this point in the history
chore: add custom models and threads api support
  • Loading branch information
louis-jan committed May 28, 2024
2 parents d7d5610 + aa2559f commit 1175b06
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
14 changes: 10 additions & 4 deletions examples/demo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,26 @@

import OpenAI from 'openai';

// gets API Key from environment variable OPENAI_API_KEY
const openai = new OpenAI();
const openai = new OpenAI({
baseURL: 'http://localhost:7331',
apiKey: 'cortex',
});

const model = 'TheBloke/TinyLlama-1.1B-Chat-v1.0-GGUF';

async function main() {
await openai.models.start(model);

// Non-streaming:
const completion = await openai.chat.completions.create({
model: 'gpt-4',
model,
messages: [{ role: 'user', content: 'Say this is a test' }],
});
console.log(completion.choices[0]?.message?.content);

// Streaming:
const stream = await openai.chat.completions.create({
model: 'gpt-4',
model,
messages: [{ role: 'user', content: 'Say this is a test' }],
stream: true,
});
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "openai",
"name": "@janhq/openai-node",
"version": "4.47.1",
"description": "The official TypeScript library for the OpenAI API",
"author": "OpenAI <[email protected]>",
"description": "Forked version of the OpenAI Node.js client library",
"author": "Jan <[email protected]>",
"types": "dist/index.d.ts",
"main": "dist/index.js",
"type": "commonjs",
"repository": "github:openai/openai-node",
"repository": "github:janhq/cortex-node",
"license": "Apache-2.0",
"packageManager": "[email protected]",
"files": [
Expand Down
7 changes: 7 additions & 0 deletions src/resources/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ export class Models extends APIResource {
del(model: string, options?: Core.RequestOptions): Core.APIPromise<ModelDeleted> {
return this._client.delete(`/models/${model}`, options);
}

/**
* Start a model instance, providing basic information about the model such as the
*/
start(model: string, options?: Core.RequestOptions): Core.APIPromise<Model> {
return this._client.post(`/models/${model}/start`, options);
}
}

/**
Expand Down

0 comments on commit 1175b06

Please sign in to comment.