Skip to content

Commit 80034f2

Browse files
committed
[feat] use model dropdown for picking a model
1 parent 35fbfaa commit 80034f2

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

Runtime/OllamaApiTest.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,22 @@ public class OllamaApiTest : MonoBehaviour
66
{
77
[SerializeField] private NeocortexChatPanel chatPanel;
88
[SerializeField] private NeocortexTextChatInput chatInput;
9+
[SerializeField] private OllamaModelDropdown modelDropdown;
910

1011
private OllamaRequest request;
1112

1213
void Start()
1314
{
1415
request = new OllamaRequest();
1516
request.OnChatResponseReceived += OnChatResponseReceived;
17+
request.ModelName = modelDropdown.options[0].text;
1618
chatInput.OnSendButtonClicked.AddListener(OnUserMessageSent);
19+
modelDropdown.onValueChanged.AddListener(OnDropdownValueChanged);
20+
}
21+
22+
private void OnDropdownValueChanged(int index)
23+
{
24+
request.ModelName = modelDropdown.options[index].text;
1725
}
1826

1927
private void OnChatResponseReceived(ChatResponse response)

Runtime/OllamaRequest.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,19 @@
88
public class OllamaRequest : WebRequest
99
{
1010
private const string BASE_URL = "http://localhost:11434/api/chat";
11+
12+
private readonly List<Message> messages = new ();
1113

14+
public string ModelName { get; set; }
1215
public event Action<ChatResponse> OnChatResponseReceived;
13-
14-
private readonly List<Message> messages = new List<Message>();
15-
16+
1617
public async void Send(string input)
1718
{
19+
if (string.IsNullOrEmpty(ModelName))
20+
{
21+
throw new Exception("ModelName property is not set.");
22+
}
23+
1824
Headers = new Dictionary<string, string>()
1925
{
2026
{ "Content-Type", "application/json" },
@@ -24,7 +30,7 @@ public async void Send(string input)
2430

2531
var data = new
2632
{
27-
model = "llama3.2:3b",
33+
model = ModelName,
2834
messages = messages.ToArray(),
2935
stream = false
3036
};

0 commit comments

Comments
 (0)