init
This commit is contained in:
86
src/test/ollama.ts
Normal file
86
src/test/ollama.ts
Normal file
@@ -0,0 +1,86 @@
|
||||
import { Ollama } from '../../../../src/provider/chat-adapter/ollama.ts';
|
||||
import util from 'util';
|
||||
const chat = new Ollama({
|
||||
baseURL: 'https://ollama.xiongxiao.me/v1',
|
||||
apiKey: 'xiongxiao2233',
|
||||
model: 'qwq:latest',
|
||||
});
|
||||
|
||||
// chat.chat([{ role: 'user', content: 'Hello, world!' }]);
|
||||
|
||||
const main = async () => {
|
||||
const res = await chat.test();
|
||||
console.log(util.inspect(res, { depth: null, colors: true }));
|
||||
};
|
||||
|
||||
// main();
|
||||
|
||||
const getJson = async () => {
|
||||
const res = await chat.chat(
|
||||
[
|
||||
{ role: 'system', content: '把发送的数据,返回给我对应的json,只处理完发送的数据。如果发送了多个,给我一个数组' },
|
||||
// { role: 'user', content: '{"name":"John","age":30}' },
|
||||
{ role: 'user', content: 'name: 张三' },
|
||||
{ role: 'user', content: 'name: 李四, age: 18' },
|
||||
],
|
||||
{
|
||||
response_format: {
|
||||
type: 'json_schema',
|
||||
json_schema: {
|
||||
name: 'user',
|
||||
description: '用户信息',
|
||||
schema: {
|
||||
type: 'object',
|
||||
// properties: {
|
||||
// name: { type: 'string' },
|
||||
// // age: { type: 'number' },
|
||||
// },
|
||||
// // required: ['name', 'age'],
|
||||
// required: ['name'],
|
||||
properties: {
|
||||
name: { type: 'string' },
|
||||
age: { type: 'number' },
|
||||
},
|
||||
required: ['name', 'age'],
|
||||
},
|
||||
},
|
||||
},
|
||||
n: 10,
|
||||
},
|
||||
);
|
||||
console.log(util.inspect(res, { depth: null, colors: true }));
|
||||
};
|
||||
|
||||
// getJson();
|
||||
|
||||
const createChat1 = async () => {
|
||||
const res = await chat.chat(
|
||||
[
|
||||
{ role: 'user', content: 'a=1, b=2, c=3' },
|
||||
{ role: 'user', content: 'a+b+c=?' },
|
||||
{ role: 'assistant', content: '给定的值为 \\( a = 1 \\), \\( b = 2 \\), \\( c = 3 \\)。\n' + '\n' + '因此,\\( a + b + c = 1 + 2 + 3 = 6 \\)。' },
|
||||
{ role: 'user', content: 'a+b+c+4=?' },
|
||||
],
|
||||
{
|
||||
model: 'qwen2.5:7b',
|
||||
},
|
||||
);
|
||||
console.log(util.inspect(res, { depth: null, colors: true }));
|
||||
};
|
||||
|
||||
// createChat1();
|
||||
|
||||
const getTags = async () => {
|
||||
const res = await chat.listModels();
|
||||
console.log(util.inspect(res, { depth: null, colors: true }));
|
||||
};
|
||||
|
||||
// getTags();
|
||||
|
||||
const getRunModels = async () => {
|
||||
const res = await chat.listRunModels();
|
||||
console.log('current', new Date().toISOString());
|
||||
console.log(util.inspect(res, { depth: null, colors: true }));
|
||||
};
|
||||
|
||||
// getRunModels();
|
||||
Reference in New Issue
Block a user