mirror of
https://github.com/aljazceru/dev-gpt.git
synced 2026-01-03 05:44:22 +01:00
Merge pull request #27 from jina-ai/feat_example_code_playground
💻 feat: example code in playground
This commit is contained in:
@@ -24,7 +24,7 @@ class Generator:
|
||||
self.test_description = test_description
|
||||
|
||||
def extract_content_from_result(self, plain_text, file_name, match_single_block=False):
|
||||
pattern = fr"^\*\*{file_name}\*\*\n```(?:\w+\n)?([\s\S]*?)```"
|
||||
pattern = fr"^\*\*{file_name}\*\*\n```(?:\w+\n)?([\s\S]*?)\n```" # the \n at the end makes sure that ``` within the generated code is not matched
|
||||
match = re.search(pattern, plain_text, re.MULTILINE)
|
||||
if match:
|
||||
return match.group(1).strip()
|
||||
|
||||
@@ -288,7 +288,7 @@ print('hello world')
|
||||
|
||||
|
||||
template_generate_playground = PromptTemplate.from_template(
|
||||
general_guidelines_string + '''
|
||||
general_guidelines_string + '''👨💻
|
||||
|
||||
{code_files_wrapped}
|
||||
|
||||
@@ -297,7 +297,7 @@ The playground must look like it was made by a professional designer.
|
||||
All the ui elements are well thought out to make them visually appealing and easy to use.
|
||||
The playground contains many emojis that fit the theme of the playground and has an emoji as favicon.
|
||||
The playground encourages the user to deploy their own microservice by clicking on this link: https://github.com/jina-ai/gptdeploy
|
||||
This is an example how you can connect to the executor assuming the document (d) is already defined:
|
||||
The playground uses the following code to send a request to the microservice:
|
||||
```
|
||||
from jina import Client, Document, DocumentArray
|
||||
client = Client(host='http://localhost:8080')
|
||||
@@ -305,7 +305,22 @@ response = client.post('/', inputs=DocumentArray([d])) # always use '/'
|
||||
print(response[0].text) # can also be blob in case of image/audio..., this should be visualized in the streamlit app
|
||||
```
|
||||
Note that the response will always be in response[0].text
|
||||
You must provide the complete app.py file with the exact same syntax to wrap the code.
|
||||
The playground displays a code block containing the microservice specific curl code that can be used to send the request to the microservice.
|
||||
Example:
|
||||
|
||||
deployment_id = os.environ.get("K8S_NAMESPACE_NAME", "")
|
||||
host = 'https://gptdeploy-{{deployment_id.split('-')[1}}.wolf.jina.ai/post' if deployment_id else "http://localhost:8080/post"
|
||||
with st.expander("See curl command"):
|
||||
st.code(
|
||||
f'curl -X \\'POST\\' \\'host\\' -H \\'accept: application/json\\' -H \\'Content-Type: application/json\\' -d \\'{{{{"data": [{{{{"text": "hello, world!"}}}}]}}}}\\''
|
||||
language='bash'
|
||||
)
|
||||
|
||||
You must provide the complete app.py file using the following syntax to wrap the code:
|
||||
**app.py**
|
||||
```python
|
||||
...
|
||||
```
|
||||
The playground (app.py) must always use the host on http://localhost:8080.
|
||||
The playground (app.py) must not let the user configure the host on the UI.
|
||||
The playground (app.py) must not import the executor.
|
||||
|
||||
Reference in New Issue
Block a user