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

Tool call serve context #468

Merged
merged 2 commits into from
Dec 3, 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
5 changes: 5 additions & 0 deletions .changeset/fluffy-crabs-obey.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@markprompt/react": patch
---

Serve context in tool call
32 changes: 32 additions & 0 deletions examples/with-embed/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<html>
<head>
<title>Embed Demo | Markprompt</title>
<style>
body {
background-color: #fafafa;
overflow: hidden;
}
#markprompt-container {
border: 1px solid #e5e5e5;
border-radius: 0.5rem;
overflow: hidden;
height: 80%;
max-height: 600px;
width: 80%;
max-width: 800px;
}
</style>
</head>
<body
style="
display: flex;
justify-content: center;
align-items: center;
width: 100vw;
height: 100vh;
"
>
<div id="markprompt-container"></div>
<script src="https://markprompt.com/embed/<YOUR-EMBED-CODE>" />
</body>
</html>
4 changes: 3 additions & 1 deletion packages/react/src/chat/store.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export interface ChatViewTool {
* OpenAI. Should validate the JSON for correctness as OpenAI can hallucinate
* arguments. Must return a string to feed the result back into OpenAI.
**/
call: (args: string) => Promise<string>;
call: (args: string, context?: { threadId: string }) => Promise<string>;
/**
* Whether user needs to confirm a call to this function or function calls
* will be executed right away.
Expand Down Expand Up @@ -570,8 +570,10 @@ export const createChatStore = ({
status: 'loading',
});

const threadId = get().threadId!;
const result = await tool.call(
tool_call.function?.arguments || '{}',
{ threadId },
);

get().setToolCallById(tool_call.id!, {
Expand Down
Loading