Skip to content

Commit 49ded21

Browse files
committed
Update provider typing. Ignore PyCharm static type checking bug.
1 parent a734b03 commit 49ded21

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

shelloracle/provider.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from abc import abstractmethod
2-
from collections.abc import AsyncGenerator
2+
from collections.abc import AsyncIterator
33
from typing import Protocol
44

55

@@ -17,7 +17,7 @@ class Provider(Protocol):
1717
name: str
1818

1919
@abstractmethod
20-
def generate(self, prompt: str) -> AsyncGenerator[str, None, None]:
20+
async def generate(self, prompt: str) -> AsyncIterator[str]:
2121
"""
2222
This is an asynchronous generator method which defines the protocol that a provider implementation
2323
should adhere to. The method takes a prompt as an argument and produces an asynchronous stream
@@ -36,6 +36,6 @@ def get_provider(name: str) -> type[Provider]:
3636
"""
3737
from .providers import Ollama
3838
providers = {
39-
"Ollama": Ollama
39+
Ollama.name: Ollama,
4040
}
4141
return providers[name]

shelloracle/providers/ollama.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import json
2-
from collections.abc import AsyncGenerator
32
from dataclasses import dataclass, asdict
4-
from typing import Any
3+
from typing import Any, AsyncIterator
54

65
import httpx
76

@@ -70,7 +69,7 @@ def endpoint(self) -> str:
7069
# computed property because python descriptors need to be bound to an instance before access
7170
return f"http://{self.host}:{self.port}/api/generate"
7271

73-
async def generate(self, prompt: str) -> AsyncGenerator[str, None, None]:
72+
async def generate(self, prompt: str) -> AsyncIterator[str]:
7473
request = GenerateRequest(self.model, prompt, system=self.system_prompt, stream=True)
7574
data = dataclass_to_json(request)
7675
try:

0 commit comments

Comments
 (0)