Files
ai/src/test/ollama.ts
2025-05-25 14:01:37 +08:00

87 lines
2.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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();