mirror of
https://github.com/Skyvern-AI/skyvern.git
synced 2026-05-01 21:20:19 +00:00
add LLMCaller that supports message history (#2204)
Some checks failed
Run tests and pre-commit / test (push) Waiting to run
Run tests and pre-commit / fe-lint-build (push) Waiting to run
Publish Fern Docs / run (push) Waiting to run
Sync to skyvern-cloud / sync (push) Waiting to run
Build Skyvern SDK and publish to PyPI / check-version-change (push) Has been cancelled
Build Skyvern SDK and publish to PyPI / run-ci (push) Has been cancelled
Build Skyvern SDK and publish to PyPI / build-sdk (push) Has been cancelled
Some checks failed
Run tests and pre-commit / test (push) Waiting to run
Run tests and pre-commit / fe-lint-build (push) Waiting to run
Publish Fern Docs / run (push) Waiting to run
Sync to skyvern-cloud / sync (push) Waiting to run
Build Skyvern SDK and publish to PyPI / check-version-change (push) Has been cancelled
Build Skyvern SDK and publish to PyPI / run-ci (push) Has been cancelled
Build Skyvern SDK and publish to PyPI / build-sdk (push) Has been cancelled
This commit is contained in:
parent
6636d949dc
commit
56cfb55096
3 changed files with 229 additions and 2 deletions
|
|
@ -1,4 +1,5 @@
|
|||
import base64
|
||||
import copy
|
||||
import json
|
||||
import re
|
||||
from typing import Any
|
||||
|
|
@ -45,6 +46,36 @@ async def llm_messages_builder(
|
|||
return [{"role": "user", "content": messages}]
|
||||
|
||||
|
||||
async def llm_messages_builder_with_history(
|
||||
prompt: str,
|
||||
screenshots: list[bytes] | None = None,
|
||||
message_history: list[dict[str, Any]] | None = None,
|
||||
) -> list[dict[str, Any]]:
|
||||
messages: list[dict[str, Any]] = []
|
||||
if message_history:
|
||||
messages = copy.deepcopy(message_history)
|
||||
current_user_messages: list[dict[str, Any]] = [
|
||||
{
|
||||
"type": "text",
|
||||
"text": prompt,
|
||||
}
|
||||
]
|
||||
|
||||
if screenshots:
|
||||
for screenshot in screenshots:
|
||||
encoded_image = base64.b64encode(screenshot).decode("utf-8")
|
||||
current_user_messages.append(
|
||||
{
|
||||
"type": "image_url",
|
||||
"image_url": {
|
||||
"url": f"data:image/png;base64,{encoded_image}",
|
||||
},
|
||||
}
|
||||
)
|
||||
messages.append({"role": "user", "content": current_user_messages})
|
||||
return messages
|
||||
|
||||
|
||||
def parse_api_response(response: litellm.ModelResponse, add_assistant_prefix: bool = False) -> dict[str, Any]:
|
||||
content = None
|
||||
try:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue