Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[repo] fix: max_tokens bug fix in completions #1887

Merged
merged 3 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public async Task<PromptResponse> CompletePromptAsync(ITurnContext turnContext,
IEnumerable<OAIChat.ChatMessage> chatMessages = prompt.Output.Select(chatMessage => chatMessage.ToOpenAIChatMessage());

ChatCompletionOptions? chatCompletionOptions = ModelReaderWriter.Read<ChatCompletionOptions>(BinaryData.FromString($@"{{
""max_tokens"": {maxInputTokens},
""max_tokens"": {promptTemplate.Configuration.Completion.MaxTokens},
""temperature"": {(float)promptTemplate.Configuration.Completion.Temperature},
""top_p"": {(float)promptTemplate.Configuration.Completion.TopP},
""presence_penalty"": {(float)promptTemplate.Configuration.Completion.PresencePenalty},
Expand Down
8 changes: 4 additions & 4 deletions python/packages/ai/teams/ai/models/openai_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ async def complete_prompt(
tokenizer: Tokenizer,
template: PromptTemplate,
) -> PromptResponse[str]:
max_tokens = template.config.completion.max_input_tokens
max_input_tokens = template.config.completion.max_input_tokens
model = (
template.config.completion.model
if template.config.completion.model is not None
Expand All @@ -134,15 +134,15 @@ async def complete_prompt(
memory=memory,
functions=functions,
tokenizer=tokenizer,
max_tokens=max_tokens,
max_tokens=max_input_tokens,
)

if res.too_long:
return PromptResponse[str](
status="too_long",
error=f"""
the generated chat completion prompt had a length of {res.length} tokens
which exceeded the max_input_tokens of {max_tokens}
which exceeded the max_input_tokens of {max_input_tokens}
""",
)

Expand Down Expand Up @@ -194,7 +194,7 @@ async def complete_prompt(
frequency_penalty=template.config.completion.frequency_penalty,
top_p=template.config.completion.top_p,
temperature=template.config.completion.temperature,
max_tokens=max_tokens,
max_tokens=template.config.completion.max_tokens,
extra_body=extra_body,
)

Expand Down
7 changes: 4 additions & 3 deletions python/packages/ai/teams/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ async def __handler__(context: TurnContext, state: StateT):
return False

feedback = context.activity.value
feedback.reply_to_id=context.activity.reply_to_id
feedback.reply_to_id = context.activity.reply_to_id

await func(context, state, feedback)
await context.send_activity(
Expand Down Expand Up @@ -819,8 +819,9 @@ async def _run_ai_chain(self, context: TurnContext, state):
return True

def _contains_non_text_attachments(self, context):
non_text_attachments = filter(lambda a: not a.content_type.startswith(
"text/html"), context.activity.attachments)
non_text_attachments = filter(
lambda a: not a.content_type.startswith("text/html"), context.activity.attachments
)
return len(list(non_text_attachments)) > 0

async def _run_after_turn_middleware(self, context: TurnContext, state):
Expand Down
Loading