mirror of
https://github.com/hwchase17/langchain
synced 2024-11-20 03:25:56 +00:00
community: Bugfix - correct Ollama API path to avoid HTTP 307 (#17895)
Sets the correct /api/generate path, without ending /, to reduce HTTP requests. Reference: https://github.com/ollama/ollama/blob/efe040f8/docs/api.md#generate-request-streaming Before: DEBUG: Starting new HTTP connection (1): localhost:11434 DEBUG: http://localhost:11434 "POST /api/generate/ HTTP/1.1" 307 0 DEBUG: http://localhost:11434 "POST /api/generate HTTP/1.1" 200 None After: DEBUG: Starting new HTTP connection (1): localhost:11434 DEBUG: http://localhost:11434 "POST /api/generate HTTP/1.1" 200 None
This commit is contained in:
parent
a53370a060
commit
ecd72d26cf
@ -159,7 +159,7 @@ class _OllamaCommon(BaseLanguageModel):
|
|||||||
yield from self._create_stream(
|
yield from self._create_stream(
|
||||||
payload=payload,
|
payload=payload,
|
||||||
stop=stop,
|
stop=stop,
|
||||||
api_url=f"{self.base_url}/api/generate/",
|
api_url=f"{self.base_url}/api/generate",
|
||||||
**kwargs,
|
**kwargs,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -174,7 +174,7 @@ class _OllamaCommon(BaseLanguageModel):
|
|||||||
async for item in self._acreate_stream(
|
async for item in self._acreate_stream(
|
||||||
payload=payload,
|
payload=payload,
|
||||||
stop=stop,
|
stop=stop,
|
||||||
api_url=f"{self.base_url}/api/generate/",
|
api_url=f"{self.base_url}/api/generate",
|
||||||
**kwargs,
|
**kwargs,
|
||||||
):
|
):
|
||||||
yield item
|
yield item
|
||||||
|
@ -32,7 +32,7 @@ def test_pass_headers_if_provided(monkeypatch: MonkeyPatch) -> None:
|
|||||||
)
|
)
|
||||||
|
|
||||||
def mock_post(url, headers, json, stream, timeout): # type: ignore[no-untyped-def]
|
def mock_post(url, headers, json, stream, timeout): # type: ignore[no-untyped-def]
|
||||||
assert url == "https://ollama-hostname:8000/api/generate/"
|
assert url == "https://ollama-hostname:8000/api/generate"
|
||||||
assert headers == {
|
assert headers == {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
"Authentication": "Bearer TEST-TOKEN-VALUE",
|
"Authentication": "Bearer TEST-TOKEN-VALUE",
|
||||||
@ -53,7 +53,7 @@ def test_handle_if_headers_not_provided(monkeypatch: MonkeyPatch) -> None:
|
|||||||
llm = Ollama(base_url="https://ollama-hostname:8000", model="foo", timeout=300)
|
llm = Ollama(base_url="https://ollama-hostname:8000", model="foo", timeout=300)
|
||||||
|
|
||||||
def mock_post(url, headers, json, stream, timeout): # type: ignore[no-untyped-def]
|
def mock_post(url, headers, json, stream, timeout): # type: ignore[no-untyped-def]
|
||||||
assert url == "https://ollama-hostname:8000/api/generate/"
|
assert url == "https://ollama-hostname:8000/api/generate"
|
||||||
assert headers == {
|
assert headers == {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
}
|
}
|
||||||
@ -73,7 +73,7 @@ def test_handle_kwargs_top_level_parameters(monkeypatch: MonkeyPatch) -> None:
|
|||||||
llm = Ollama(base_url="https://ollama-hostname:8000", model="foo", timeout=300)
|
llm = Ollama(base_url="https://ollama-hostname:8000", model="foo", timeout=300)
|
||||||
|
|
||||||
def mock_post(url, headers, json, stream, timeout): # type: ignore[no-untyped-def]
|
def mock_post(url, headers, json, stream, timeout): # type: ignore[no-untyped-def]
|
||||||
assert url == "https://ollama-hostname:8000/api/generate/"
|
assert url == "https://ollama-hostname:8000/api/generate"
|
||||||
assert headers == {
|
assert headers == {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
}
|
}
|
||||||
@ -119,7 +119,7 @@ def test_handle_kwargs_with_unknown_param(monkeypatch: MonkeyPatch) -> None:
|
|||||||
llm = Ollama(base_url="https://ollama-hostname:8000", model="foo", timeout=300)
|
llm = Ollama(base_url="https://ollama-hostname:8000", model="foo", timeout=300)
|
||||||
|
|
||||||
def mock_post(url, headers, json, stream, timeout): # type: ignore[no-untyped-def]
|
def mock_post(url, headers, json, stream, timeout): # type: ignore[no-untyped-def]
|
||||||
assert url == "https://ollama-hostname:8000/api/generate/"
|
assert url == "https://ollama-hostname:8000/api/generate"
|
||||||
assert headers == {
|
assert headers == {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
}
|
}
|
||||||
@ -166,7 +166,7 @@ def test_handle_kwargs_with_options(monkeypatch: MonkeyPatch) -> None:
|
|||||||
llm = Ollama(base_url="https://ollama-hostname:8000", model="foo", timeout=300)
|
llm = Ollama(base_url="https://ollama-hostname:8000", model="foo", timeout=300)
|
||||||
|
|
||||||
def mock_post(url, headers, json, stream, timeout): # type: ignore[no-untyped-def]
|
def mock_post(url, headers, json, stream, timeout): # type: ignore[no-untyped-def]
|
||||||
assert url == "https://ollama-hostname:8000/api/generate/"
|
assert url == "https://ollama-hostname:8000/api/generate"
|
||||||
assert headers == {
|
assert headers == {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user