-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathClient.cs
More file actions
46 lines (42 loc) · 1.64 KB
/
Client.cs
File metadata and controls
46 lines (42 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
using System;
using System.Collections.Generic;
using System.Threading;
using UndreamAI.LlamaLib;
namespace LlamaLibExamples
{
class Client
{
static string previousText = "";
static void StreamingCallback(string text)
{
Console.Write(text.Substring(previousText.Length));
previousText = text;
}
static void Main(string[] args)
{
string serverUrl = "http://localhost";
string prompt = "Hello, how are you?";
int serverPort = 13333;
Console.WriteLine("*** Using client ***");
// Create a remote client that connects to the server
LLMClient llmClient = new LLMClient(serverUrl, serverPort);
Console.WriteLine("----------------------- tokenize -----------------------");
List<int> tokens = llmClient.Tokenize(prompt);
Console.Write("tokens: ");
foreach (int token in tokens)
{
Console.Write($"{token} ");
}
Console.WriteLine();
// Create an agent that uses the remote client
Console.WriteLine("*** Using agent ***");
string systemPrompt = "You are a helpful AI assistant. Be concise and friendly.";
LLMAgent agent = new LLMAgent(llmClient, systemPrompt);
Console.WriteLine("\n----------------------- completion (streaming) using agent -----------------------");
Console.WriteLine("User: " + prompt);
Console.Write("Assistant: ");
llmClient.Completion(prompt, StreamingCallback);
Console.WriteLine();
}
}
}