Merge pull request #27 from jina-ai/feat_example_code_playground

💻 feat: example code in playground
This commit is contained in:
Florian Hönicke
2023-04-20 16:58:14 +02:00
committed by GitHub
3 changed files with 21 additions and 6 deletions

View File

@@ -6,7 +6,7 @@ GPT Deploy: One line to generate them all 🧙🚀
<img src="res/gpt-deploy-logo.png" alt="Jina NOW logo" width="150px">
</p>
<p align="center">
Turn your natural language descriptions into fully functional, deployed microservices with a single command!
Turn your natural language descriptions into fully functional, deployed AI-powered microservices with a single command!
Your imagination is the limit!
</p>
@@ -37,7 +37,7 @@ Your imagination is the limit!
[![Watch the video](res/thumbnail.png)](https://user-images.githubusercontent.com/11627845/231530421-272a66aa-4260-4e17-ab7a-ba66adca754c.mp4)
</p>
This project streamlines the creation and deployment of microservices.
This project streamlines the creation and deployment of AI-powered microservices.
Simply describe your task using natural language, and the system will automatically build and deploy your microservice.
To ensure the microservice accurately aligns with your intended task a test scenario is required.

View File

@@ -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()

View File

@@ -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.