support api_endpoint for ollama

This commit is contained in:
lux 2024-06-10 17:03:46 +08:00
parent e88c920120
commit f354834e9f
4 changed files with 8 additions and 4 deletions

2
Cargo.lock generated
View File

@ -1518,7 +1518,7 @@ dependencies = [
[[package]]
name = "lsp-ai"
version = "0.1.0"
version = "0.2.1"
dependencies = [
"anyhow",
"assert_cmd",

View File

@ -1,6 +1,6 @@
[package]
name = "lsp-ai"
version = "0.2.0"
version = "0.2.1"
edition = "2021"
license = "MIT"
description = "LSP-AI is an open-source language server that serves as a backend for AI-powered functionality, designed to assist and empower software engineers, not replace them."

View File

@ -94,6 +94,8 @@ const fn n_ctx_default() -> u32 {
#[derive(Clone, Debug, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct Ollama {
// api endpoint
pub api_endpoint: Option<String>,
// The model name
pub model: String,
// The maximum requests per second

View File

@ -66,8 +66,9 @@ impl Ollama {
params: OllamaRunParams,
) -> anyhow::Result<String> {
let client = reqwest::Client::new();
let api: &String = self.configuration.api_endpoint.as_ref().expect("http://localhost:11434");
let res: OllamaCompletionsResponse = client
.post("http://localhost:11434/api/generate")
.post(format!("{}/api/generate",api))
.header("Content-Type", "application/json")
.header("Accept", "application/json")
.json(&json!({
@ -100,8 +101,9 @@ impl Ollama {
params: OllamaRunParams,
) -> anyhow::Result<String> {
let client = reqwest::Client::new();
let api: &String = self.configuration.api_endpoint.as_ref().expect("http://localhost:11434");
let res: OllamaChatResponse = client
.post("http://localhost:11434/api/chat")
.post(format!("{}/api/chat",api))
.header("Content-Type", "application/json")
.header("Accept", "application/json")
.json(&json!({