mirror of
https://github.com/ollama/ollama-python.git
synced 2026-05-01 11:48:17 +08:00
Support api/embed (#208)
* api/embed * api/embed * api/embed * rm legacy
This commit is contained in:
parent
359c63daa7
commit
b0ea6d9e44
@ -21,6 +21,7 @@ __all__ = [
|
||||
'ResponseError',
|
||||
'generate',
|
||||
'chat',
|
||||
'embed',
|
||||
'embeddings',
|
||||
'pull',
|
||||
'push',
|
||||
@ -36,6 +37,7 @@ _client = Client()
|
||||
|
||||
generate = _client.generate
|
||||
chat = _client.chat
|
||||
embed = _client.embed
|
||||
embeddings = _client.embeddings
|
||||
pull = _client.pull
|
||||
push = _client.push
|
||||
|
||||
@ -243,6 +243,29 @@ class Client(BaseClient):
|
||||
stream=stream,
|
||||
)
|
||||
|
||||
def embed(
|
||||
self,
|
||||
model: str = '',
|
||||
input: Union[str, Sequence[AnyStr]] = '',
|
||||
truncate: bool = True,
|
||||
options: Optional[Options] = None,
|
||||
keep_alive: Optional[Union[float, str]] = None,
|
||||
) -> Mapping[str, Any]:
|
||||
if not model:
|
||||
raise RequestError('must provide a model')
|
||||
|
||||
return self._request(
|
||||
'POST',
|
||||
'/api/embed',
|
||||
json={
|
||||
'model': model,
|
||||
'input': input,
|
||||
'truncate': truncate,
|
||||
'options': options or {},
|
||||
'keep_alive': keep_alive,
|
||||
},
|
||||
).json()
|
||||
|
||||
def embeddings(
|
||||
self,
|
||||
model: str = '',
|
||||
@ -634,6 +657,31 @@ class AsyncClient(BaseClient):
|
||||
stream=stream,
|
||||
)
|
||||
|
||||
async def embed(
|
||||
self,
|
||||
model: str = '',
|
||||
input: Union[str, Sequence[AnyStr]] = '',
|
||||
truncate: bool = True,
|
||||
options: Optional[Options] = None,
|
||||
keep_alive: Optional[Union[float, str]] = None,
|
||||
) -> Mapping[str, Any]:
|
||||
if not model:
|
||||
raise RequestError('must provide a model')
|
||||
|
||||
response = await self._request(
|
||||
'POST',
|
||||
'/api/embed',
|
||||
json={
|
||||
'model': model,
|
||||
'input': input,
|
||||
'truncate': truncate,
|
||||
'options': options or {},
|
||||
'keep_alive': keep_alive,
|
||||
},
|
||||
)
|
||||
|
||||
return response.json()
|
||||
|
||||
async def embeddings(
|
||||
self,
|
||||
model: str = '',
|
||||
|
||||
Loading…
Reference in New Issue
Block a user