C
C#2mo ago
headrx

Ollama 404 http denial

Im attemping to write a Ollama front end and am having connection issues. Here is my http connection code.
csharp
private async void Send_Message(string message)
{
using (HttpClient client = new HttpClient())
{
var requestData = new
{
model = "llama3.2",
prompt = message,
stream = true
};
client.BaseAddress = new Uri("http://localhost:11434/api/generate");

string jsonRequest = JsonSerializer.Serialize(requestData);
var content = new StringContent(jsonRequest, System.Text.Encoding.UTF8, "application/json");

// Send post request to the model
HttpResponseMessage response = await client.PostAsync(client.BaseAddress, content);
response.EnsureSuccessStatusCode();
string jsonResponse = await response.Content.ReadAsStringAsync();

ApiResponse apiResponse = JsonSerializer.Deserialize<ApiResponse>(jsonResponse);
rtxtboxResponse.Document.Blocks.Add(new Paragraph(new Run(apiResponse.Response)));
}

}
csharp
private async void Send_Message(string message)
{
using (HttpClient client = new HttpClient())
{
var requestData = new
{
model = "llama3.2",
prompt = message,
stream = true
};
client.BaseAddress = new Uri("http://localhost:11434/api/generate");

string jsonRequest = JsonSerializer.Serialize(requestData);
var content = new StringContent(jsonRequest, System.Text.Encoding.UTF8, "application/json");

// Send post request to the model
HttpResponseMessage response = await client.PostAsync(client.BaseAddress, content);
response.EnsureSuccessStatusCode();
string jsonResponse = await response.Content.ReadAsStringAsync();

ApiResponse apiResponse = JsonSerializer.Deserialize<ApiResponse>(jsonResponse);
rtxtboxResponse.Document.Blocks.Add(new Paragraph(new Run(apiResponse.Response)));
}

}
curl localhost:11434/api/generate -d "{\"model\":\"llama3.2:latest\",\"prompt\":\"hi\",\"stream\":false}"
curl localhost:11434/api/generate -d "{\"model\":\"llama3.2:latest\",\"prompt\":\"hi\",\"stream\":false}"
I am able to curl , as well as just browse to the base url to show connectivity via browser , so i know its correctly running. If i curl to the BaseAddress with the request data included it correctly works, btu i cant get my code ot connect at all. It 404's me all day. Any ideas ?
No description
No description
1 Reply
headrx
headrxOP2mo ago
Heres my ApiResponse class just for reference
public class ApiResponse
{
public string Model { get; set; }
public string CreatedAt { get; set; }
public string Response { get; set; }
public bool Done { get; set; }
public string DoneReason { get; set; }
public int[] Context { get; set; }
public long TotalDuration { get; set; }
public long LoadDuration { get; set; }
public int PromptEvalCount { get; set; }
public long PromptEvalDuration { get; set; }
public int EvalCount { get; set; }
public long EvalDuration { get; set; }
}
public class ApiResponse
{
public string Model { get; set; }
public string CreatedAt { get; set; }
public string Response { get; set; }
public bool Done { get; set; }
public string DoneReason { get; set; }
public int[] Context { get; set; }
public long TotalDuration { get; set; }
public long LoadDuration { get; set; }
public int PromptEvalCount { get; set; }
public long PromptEvalDuration { get; set; }
public int EvalCount { get; set; }
public long EvalDuration { get; set; }
}
Does anyone know of what im doing wrong ? also tried 127.0.0.1 instead of localhost

Did you find this page helpful?