Skip to content

Implement conversation context and streaming with OllamaSharp #310

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Dec 3, 2024
Merged
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
24b9e88
Implement settings file for Ollama agent
kborowinski Nov 19, 2024
f5c0ee4
Merge branch 'main' into ollama-settings
kborowinski Nov 19, 2024
cdcc98e
Update readme and links to the documentation; Handle http exception d…
kborowinski Nov 19, 2024
c0f8389
Implement config file watcher to reload settings on change
kborowinski Nov 19, 2024
0899ddb
Do not force user to specify complete endpoint URL, just IP address a…
kborowinski Nov 19, 2024
bcc5d1e
Change json to config so comments are not rendered on GitHub in red
kborowinski Nov 19, 2024
9c358b8
Revert to json and update the comments in the config file
kborowinski Nov 19, 2024
336a3c3
Merge branch 'PowerShell:main' into ollama-settings
kborowinski Nov 19, 2024
9b57754
Add model and endpoint self check; Change warnings to errors; Fix pos…
kborowinski Nov 20, 2024
d9d6fac
Switch to OllamaSharp nuget package to simplify agent code and suppor…
kborowinski Nov 21, 2024
464d633
Add context support
kborowinski Nov 21, 2024
fe68d94
Reset context on refresh
kborowinski Nov 22, 2024
fd95d98
Implement changes as suggested in the code review
kborowinski Nov 23, 2024
ee76005
Add missing new line at the end of file
kborowinski Nov 23, 2024
a217daa
Merge branch 'main' into ollama-sharp
kborowinski Nov 23, 2024
cdbee04
Check if ollama is running only for local endpoint
kborowinski Nov 24, 2024
29b4c49
Update description and readme that ollama is also supported remotely;…
kborowinski Nov 24, 2024
b798172
Minor updates
daxian-dbw Dec 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Check if ollama is running only for local endpoint
  • Loading branch information
kborowinski committed Nov 24, 2024
commit cdbee047e896f04e77d0078e6920470909cbdbd2
12 changes: 10 additions & 2 deletions shell/agents/AIShell.Ollama.Agent/OllamaAgent.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
using System.Diagnostics;
using System.Text;
using System.Text.Json;
using System.Text.RegularExpressions;
using AIShell.Abstraction;
using OllamaSharp;
using OllamaSharp.Models;

namespace AIShell.Ollama.Agent;

public sealed class OllamaAgent : ILLMAgent
public sealed partial class OllamaAgent : ILLMAgent
{
private bool _reloadSettings;
private bool _isDisposed;
Expand Down Expand Up @@ -164,7 +165,7 @@ public async Task<bool> ChatAsync(string input, IShell shell)
// Reload the setting file if needed.
ReloadSettings();

if (Process.GetProcessesByName("ollama").Length is 0)
if (IsLocalHost().IsMatch(_client.Uri.Host) && Process.GetProcessesByName("ollama").Length is 0)
{
host.WriteErrorLine("Please be sure the Ollama is installed and server is running. Check all the prerequisites in the README of this agent are met.");
return false;
Expand Down Expand Up @@ -317,4 +318,11 @@ private void NewExampleSettingFile()
""";
File.WriteAllText(SettingFile, SampleContent, Encoding.UTF8);
}

/// <summary>
/// Defines a source-generated regular expression to match localhost addresses
/// (e.g., "localhost", "127.0.0.1", "::1") with case-insensitivity.
/// </summary>
[GeneratedRegex("^(localhost|127\\.0\\.0\\.1|::1)$", RegexOptions.IgnoreCase)]
internal partial Regex IsLocalHost();
}