瀏覽代碼

generate example

Bruce MacDonald 1 年之前
父節點
當前提交
65d81a769d
共有 3 個文件被更改,包括 22 次插入3 次删除
  1. 2 3
      examples/fill-in-middle/fill.ts
  2. 11 0
      examples/generate-stream/generate.ts
  3. 9 0
      examples/generate/generate.ts

+ 2 - 3
examples/fill-in-middle/fill.ts

@@ -7,10 +7,9 @@ async function main(): Promise<void> {
     const suffix = `
 return result
 `;
-
-    const respose = await new Ollama().generate({model: "codellama:7b-code", prompt: `<PRE> ${prefix} <SUF>${suffix} <MID>`, options: {num_predict: 128, temperature: 0, top_p: 0.9, presence_penalty: 0, stop: ["<EOT>"]}});
+    const client: Ollama = new Ollama();
+    const respose = await client.generate({model: "codellama:7b-code", prompt: `<PRE> ${prefix} <SUF>${suffix} <MID>`, options: {num_predict: 128, temperature: 0, top_p: 0.9, presence_penalty: 0, stop: ["<EOT>"]}});
     console.log(respose.response);
-
 }
 
 await main();

+ 11 - 0
examples/generate-stream/generate.ts

@@ -0,0 +1,11 @@
+import { Ollama } from '../../src/index';
+
+async function main(): Promise<void> {
+    const client: Ollama = new Ollama();
+    const stream = await client.generate({model: "mistral", prompt: "Why is the sky blue?", stream: true});
+    for await (const part of stream) {
+        process.stdout.write(part.response);
+    }
+}
+
+await main();

+ 9 - 0
examples/generate/generate.ts

@@ -0,0 +1,9 @@
+import { Ollama } from '../../src/index';
+
+async function main(): Promise<void> {
+    const client: Ollama = new Ollama();
+    const respose = await client.generate({model: "mistral", prompt: "Why is the sky blue?"});
+    console.log(respose.response);
+}
+
+await main();