Skip to content

Commit

Permalink
Add param to change number of generated responses (#180)
Browse files Browse the repository at this point in the history
* add param to generate n responses from openai api

* add default num_responses param value
  • Loading branch information
lindiatjuatja authored Aug 21, 2023
1 parent 332d132 commit d349ff5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
7 changes: 3 additions & 4 deletions zeno_build/models/chat_generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def generate_from_chat_prompt(
max_tokens: int,
top_p: float,
context_length: int,
num_responses: int = 1,
requests_per_minute: int = 150,
) -> list[str]:
"""Generate from a list of chat-style prompts.
Expand All @@ -57,7 +58,6 @@ def generate_from_chat_prompt(
f"{temperature=}, {max_tokens=}, {top_p=}, {context_length=}..."
)
if model_config.provider == "openai":
response_per_api_call = 1
return asyncio.run(
generate_from_openai_completion(
_contexts_to_prompts(
Expand All @@ -66,21 +66,20 @@ def generate_from_chat_prompt(
model_config,
temperature,
max_tokens,
response_per_api_call,
num_responses,
top_p,
requests_per_minute,
)
)
elif model_config.provider == "openai_chat":
response_per_api_call = 1
return asyncio.run(
generate_from_openai_chat_completion(
full_contexts,
prompt_template,
model_config,
temperature,
max_tokens,
response_per_api_call,
num_responses,
top_p,
context_length,
requests_per_minute,
Expand Down
5 changes: 3 additions & 2 deletions zeno_build/models/text_generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def generate_from_text_prompt(
temperature: float,
max_tokens: int,
top_p: float,
num_responses: int = 1,
requests_per_minute: int = 150,
) -> list[str]:
"""Generate from a textual prompt.
Expand All @@ -31,6 +32,7 @@ def generate_from_text_prompt(
model_config: Configuration of the model.
temperature: The temperature to use.
max_tokens: The maximum number of tokens to generate.
num_responses: The number of responses to generate.
top_p: The top p value to use.
requests_per_minute: Limit on the number of OpenAI requests per minute.
Expand All @@ -51,15 +53,14 @@ def generate_from_text_prompt(
top_p,
)
elif model_config.provider == "openai":
response_per_api_call = 1
prompts = [replace_variables(prompt_template, vars) for vars in variables]
return asyncio.run(
generate_from_openai_completion(
prompts,
model_config,
temperature,
max_tokens,
response_per_api_call,
num_responses,
top_p,
requests_per_minute,
)
Expand Down

0 comments on commit d349ff5

Please sign in to comment.