-
Notifications
You must be signed in to change notification settings - Fork 299
Adding a simpler "test" widget and server. #38
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
Open
gregmercer
wants to merge
10
commits into
openai:main
Choose a base branch
from
gregmercer:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+413
−0
Open
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
3210206
Adding a simpler "test" widget and server.
gregmercer ce96dfb
Moving test_server_python to top folder.
gregmercer e447be1
Updating the README.md
gregmercer a87cfe0
Updating the README.md
gregmercer 86b161b
Handling how toolOutput now seems to be coming back differently.
gregmercer a7c49bf
Fixing the use of callTool.
gregmercer 9f7cd66
Changing to href for call to openExternal.
gregmercer 5b1faca
Update README.md
gregmercer 8f58e8d
Removing uv.lock, pyproject.toml and .python-version.
gregmercer 64a6592
Removing README.md file for the test_server_python.
gregmercer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| [project] | ||
| name = "todos-server-python" | ||
| version = "0.1.0" | ||
| description = "Add your description here" | ||
| readme = "README.md" | ||
| requires-python = ">=3.11" | ||
| dependencies = [ | ||
| "fastapi>=0.118.2", | ||
| "mcp[fastapi]>=1.16.0", | ||
| "uvicorn>=0.37.0", | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| import { createRoot } from "react-dom/client"; | ||
| import App from "./test"; | ||
|
|
||
| createRoot(document.getElementById("test-root")).render(<App />); | ||
|
|
||
| export { App }; | ||
| export default App; |
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| import React from "react"; | ||
| import { useWidgetProps } from "../use-widget-props"; | ||
| import { useWidgetState } from "../use-widget-state"; | ||
| import { useDisplayMode } from "../use-display-mode"; | ||
| import { useEffect } from "react"; | ||
|
|
||
| const ExpandIcon = () => { | ||
| return ( | ||
| <svg | ||
| width="20" | ||
| height="20" | ||
| viewBox="0 0 20 20" | ||
| fill="currentColor" | ||
| xmlns="http://www.w3.org/2000/svg" | ||
| > | ||
| <path d="M4.33496 11C4.33496 10.6327 4.63273 10.335 5 10.335C5.36727 10.335 5.66504 10.6327 5.66504 11V14.335H9L9.13379 14.3486C9.43692 14.4106 9.66504 14.6786 9.66504 15C9.66504 15.3214 9.43692 15.5894 9.13379 15.6514L9 15.665H5C4.63273 15.665 4.33496 15.3673 4.33496 15V11ZM14.335 9V5.66504H11C10.6327 5.66504 10.335 5.36727 10.335 5C10.335 4.63273 10.6327 4.33496 11 4.33496H15L15.1338 4.34863C15.4369 4.41057 15.665 4.67857 15.665 5V9C15.665 9.36727 15.3673 9.66504 15 9.66504C14.6327 9.66504 14.335 9.36727 14.335 9Z" /> | ||
| </svg> | ||
| ); | ||
| }; | ||
|
|
||
| export function App() { | ||
| const widgetProps = useWidgetProps() || {}; | ||
| const { title_text = 'hi' } = widgetProps; | ||
| const displayMode = useDisplayMode(); | ||
| const maxHeight = "100vh"; | ||
|
|
||
| const [titleText, setTitleText] = useWidgetState(title_text); | ||
| const [isLoading, setIsLoading] = useWidgetState(false); | ||
|
|
||
| useEffect(() => { | ||
| setTitleText(title_text); | ||
| }, [title_text, setTitleText]); | ||
|
|
||
| const helloAgain = async () => { | ||
| //await window.openai.sendFollowUpMessage({ "prompt": "can you show the test app again with the title 'hello again.'" }); | ||
| setIsLoading(true); | ||
| try { | ||
| const reply = await window.openai.callTool("test-tool", { | ||
| "title_text": "hi again. :)" | ||
| }); | ||
| if (reply?.structuredContent?.title_text) { | ||
| setTitleText(reply.structuredContent.title_text); | ||
| } | ||
| } finally { | ||
| setIsLoading(false); | ||
| } | ||
| }; | ||
|
|
||
| const gotoDoc = () => { | ||
| window.openai.openExternal({ href: "https://developers.openai.com/apps-sdk" }); | ||
| }; | ||
|
|
||
| return ( | ||
| <div | ||
| className={`antialiased w-full relative bg-blue-300 overflow-hidden ${displayMode !== "fullscreen" ? "aspect-[640/480] sm:aspect-[640/400]" : "" | ||
| }`} | ||
| style={{ | ||
| maxHeight, | ||
| height: displayMode === "fullscreen" ? maxHeight : undefined, | ||
| }} | ||
| > | ||
| {displayMode !== "fullscreen" && ( | ||
| <div className="fixed end-3 z-20 top-3 aspect-square rounded-full p-2 bg-white/20 text-white backdrop-blur-lg"> | ||
| <button | ||
| onClick={() => { | ||
| window.openai.requestDisplayMode({ mode: "fullscreen" }); | ||
| }} | ||
| > | ||
| <ExpandIcon /> | ||
| </button> | ||
| </div> | ||
| )} | ||
|
|
||
| <div style={{ | ||
| position: 'absolute', | ||
| top: 0, | ||
| left: 0, | ||
| padding: '16px', | ||
| fontSize: '18px', | ||
| fontWeight: 'bold' | ||
| }}> | ||
| <div>{titleText || 'hi'}</div> | ||
| <button | ||
| onClick={helloAgain} | ||
| disabled={isLoading} | ||
| style={{ | ||
| marginTop: '10px', | ||
| padding: '8px 16px', | ||
| fontSize: '14px', | ||
| backgroundColor: 'green', | ||
| color: 'white', | ||
| border: 'none', | ||
| borderRadius: '4px', | ||
| cursor: isLoading ? 'wait' : 'pointer' | ||
| }} | ||
| > | ||
| {isLoading ? 'Loading...' : 'Say hello again'} | ||
| </button> | ||
| <button | ||
| onClick={gotoDoc} | ||
| style={{ | ||
| marginTop: '10px', | ||
| marginLeft: '10px', | ||
| padding: '8px 16px', | ||
| fontSize: '14px', | ||
| cursor: 'pointer', | ||
| backgroundColor: 'green', | ||
| color: 'white', | ||
| border: 'none', | ||
| borderRadius: '4px' | ||
| }} | ||
| > | ||
| Go to Apps SDK doc | ||
| </button> | ||
| </div> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| export default App; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to make it consistent with other examples, could you remove the pyproject.toml + uv.lock & .python-version?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok... I've removed these files.