Skip to content

Commit

Permalink
add insert support to generate endpoint (#215)
Browse files Browse the repository at this point in the history
* add suffix

* update fill-in-the-middle example

* keep example

* lint

* variables
  • Loading branch information
royjhan authored Jul 18, 2024
1 parent b0ea6d9 commit 33c4b61
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
6 changes: 3 additions & 3 deletions examples/fill-in-middle/main.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
from ollama import generate

prefix = '''def remove_non_ascii(s: str) -> str:
prompt = '''def remove_non_ascii(s: str) -> str:
""" '''

suffix = """
return result
"""


response = generate(
model='codellama:7b-code',
prompt=f'<PRE> {prefix} <SUF>{suffix} <MID>',
prompt=prompt,
suffix=suffix,
options={
'num_predict': 128,
'temperature': 0,
Expand Down
8 changes: 8 additions & 0 deletions ollama/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ def generate(
self,
model: str = '',
prompt: str = '',
suffix: str = '',
system: str = '',
template: str = '',
context: Optional[Sequence[int]] = None,
Expand All @@ -118,6 +119,7 @@ def generate(
self,
model: str = '',
prompt: str = '',
suffix: str = '',
system: str = '',
template: str = '',
context: Optional[Sequence[int]] = None,
Expand All @@ -133,6 +135,7 @@ def generate(
self,
model: str = '',
prompt: str = '',
suffix: str = '',
system: str = '',
template: str = '',
context: Optional[Sequence[int]] = None,
Expand Down Expand Up @@ -162,6 +165,7 @@ def generate(
json={
'model': model,
'prompt': prompt,
'suffix': suffix,
'system': system,
'template': template,
'context': context or [],
Expand Down Expand Up @@ -518,6 +522,7 @@ async def generate(
self,
model: str = '',
prompt: str = '',
suffix: str = '',
system: str = '',
template: str = '',
context: Optional[Sequence[int]] = None,
Expand All @@ -534,6 +539,7 @@ async def generate(
self,
model: str = '',
prompt: str = '',
suffix: str = '',
system: str = '',
template: str = '',
context: Optional[Sequence[int]] = None,
Expand All @@ -549,6 +555,7 @@ async def generate(
self,
model: str = '',
prompt: str = '',
suffix: str = '',
system: str = '',
template: str = '',
context: Optional[Sequence[int]] = None,
Expand Down Expand Up @@ -577,6 +584,7 @@ async def generate(
json={
'model': model,
'prompt': prompt,
'suffix': suffix,
'system': system,
'template': template,
'context': context or [],
Expand Down
6 changes: 6 additions & 0 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ def test_client_generate(httpserver: HTTPServer):
json={
'model': 'dummy',
'prompt': 'Why is the sky blue?',
'suffix': '',
'system': '',
'template': '',
'context': [],
Expand Down Expand Up @@ -182,6 +183,7 @@ def generate():
json={
'model': 'dummy',
'prompt': 'Why is the sky blue?',
'suffix': '',
'system': '',
'template': '',
'context': [],
Expand Down Expand Up @@ -210,6 +212,7 @@ def test_client_generate_images(httpserver: HTTPServer):
json={
'model': 'dummy',
'prompt': 'Why is the sky blue?',
'suffix': '',
'system': '',
'template': '',
'context': [],
Expand Down Expand Up @@ -619,6 +622,7 @@ async def test_async_client_generate(httpserver: HTTPServer):
json={
'model': 'dummy',
'prompt': 'Why is the sky blue?',
'suffix': '',
'system': '',
'template': '',
'context': [],
Expand Down Expand Up @@ -659,6 +663,7 @@ def generate():
json={
'model': 'dummy',
'prompt': 'Why is the sky blue?',
'suffix': '',
'system': '',
'template': '',
'context': [],
Expand Down Expand Up @@ -688,6 +693,7 @@ async def test_async_client_generate_images(httpserver: HTTPServer):
json={
'model': 'dummy',
'prompt': 'Why is the sky blue?',
'suffix': '',
'system': '',
'template': '',
'context': [],
Expand Down

0 comments on commit 33c4b61

Please sign in to comment.