-
Notifications
You must be signed in to change notification settings - Fork 3
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
125 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
{ | ||
"name": "@xsai/model", | ||
"version": "0.0.15", | ||
"type": "module", | ||
"author": "Moeru AI", | ||
"license": "MIT", | ||
"homepage": "https://xsai.js.org", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/moeru-ai/xsai.git", | ||
"directory": "packages/model" | ||
}, | ||
"bugs": "https://github.com/moeru-ai/xsai/issues", | ||
"main": "./dist/index.js", | ||
"types": "./dist/index.d.ts", | ||
"exports": { | ||
".": { | ||
"types": "./dist/index.d.ts", | ||
"default": "./dist/index.js" | ||
} | ||
}, | ||
"files": [ | ||
"dist" | ||
], | ||
"scripts": { | ||
"build": "pkgroll", | ||
"build:watch": "pkgroll --watch", | ||
"test": "vitest run", | ||
"test:watch": "vitest" | ||
}, | ||
"dependencies": { | ||
"@xsai/shared": "workspace:" | ||
}, | ||
"devDependencies": { | ||
"@xsai/providers": "workspace:" | ||
} | ||
} |
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,2 @@ | ||
export type * from './types' | ||
export * from './utils' |
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 @@ | ||
export type { Model } from './model' |
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,6 @@ | ||
export interface Model { | ||
created: number | ||
id: string | ||
object: 'model' | ||
owned_by: string | ||
} |
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,2 @@ | ||
export * from './list-models' | ||
export * from './retrieve-model' |
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,21 @@ | ||
import { type CommonRequestOptions, requestHeaders } from '@xsai/shared' | ||
|
||
import type { Model } from '../types/model' | ||
|
||
export interface ListModelsOptions extends Omit<CommonRequestOptions, 'model'> {} | ||
|
||
export interface ListModelsResponse { | ||
data: Model[] | ||
object: 'list' | ||
} | ||
|
||
export const listModels = async (options: ListModelsOptions): Promise<Model[]> => | ||
await fetch(options.url, { | ||
headers: requestHeaders({ | ||
'Content-Type': 'application/json', | ||
...options.headers, | ||
}, options.apiKey), | ||
signal: options.abortSignal, | ||
}) | ||
.then(res => res.json() as Promise<ListModelsResponse>) | ||
.then(({ data }) => data) |
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,15 @@ | ||
import { type CommonRequestOptions, requestHeaders } from '@xsai/shared' | ||
|
||
import type { Model } from '../types/model' | ||
|
||
export interface RetrieveModelOptions extends Omit<CommonRequestOptions, 'model'> {} | ||
|
||
export const retrieveModel = async (options: RetrieveModelOptions): Promise<Model> => | ||
await fetch(options.url, { | ||
headers: requestHeaders({ | ||
'Content-Type': 'application/json', | ||
...options.headers, | ||
}, options.apiKey), | ||
signal: options.abortSignal, | ||
}) | ||
.then(res => res.json() as Promise<Model>) |
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,27 @@ | ||
import { describe, expect, it } from 'vitest' | ||
|
||
import { listModels, retrieveModel } from '../src' | ||
|
||
describe('@xsai/model', () => { | ||
it('listModels', async () => { | ||
const models = await listModels({ | ||
url: new URL('models', 'http://localhost:11434/v1/'), | ||
}) | ||
|
||
const llama = models.find(({ id }) => id === 'llama3.2:latest')! | ||
|
||
expect(llama.id).toBe('llama3.2:latest') | ||
expect(llama.object).toBe('model') | ||
expect(llama.owned_by).toBe('library') | ||
}) | ||
|
||
it('retrieveModel', async () => { | ||
const llama = await retrieveModel({ | ||
url: new URL('models/llama3.2:latest', 'http://localhost:11434/v1/'), | ||
}) | ||
|
||
expect(llama.id).toBe('llama3.2:latest') | ||
expect(llama.object).toBe('model') | ||
expect(llama.owned_by).toBe('library') | ||
}) | ||
}) |
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,4 @@ | ||
{ | ||
"extends": "@importantimport/tsconfig/app.json", | ||
"include": ["src"] | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.