mirror of
https://github.com/ollama/ollama-python.git
synced 2026-09-08 04:09:54 +00:00
Support api/embed (#208)
* api/embed * api/embed * api/embed * rm legacy
This commit is contained in:
@@ -21,6 +21,7 @@ __all__ = [
|
|||||||
'ResponseError',
|
'ResponseError',
|
||||||
'generate',
|
'generate',
|
||||||
'chat',
|
'chat',
|
||||||
|
'embed',
|
||||||
'embeddings',
|
'embeddings',
|
||||||
'pull',
|
'pull',
|
||||||
'push',
|
'push',
|
||||||
@@ -36,6 +37,7 @@ _client = Client()
|
|||||||
|
|
||||||
generate = _client.generate
|
generate = _client.generate
|
||||||
chat = _client.chat
|
chat = _client.chat
|
||||||
|
embed = _client.embed
|
||||||
embeddings = _client.embeddings
|
embeddings = _client.embeddings
|
||||||
pull = _client.pull
|
pull = _client.pull
|
||||||
push = _client.push
|
push = _client.push
|
||||||
|
|||||||
@@ -243,6 +243,29 @@ class Client(BaseClient):
|
|||||||
stream=stream,
|
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(
|
def embeddings(
|
||||||
self,
|
self,
|
||||||
model: str = '',
|
model: str = '',
|
||||||
@@ -634,6 +657,31 @@ class AsyncClient(BaseClient):
|
|||||||
stream=stream,
|
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(
|
async def embeddings(
|
||||||
self,
|
self,
|
||||||
model: str = '',
|
model: str = '',
|
||||||
|
|||||||
Reference in New Issue
Block a user