Merge branch 'main' of github.com:jina-ai/microchain into feat-avoid-loop

This commit is contained in:
Florian Hönicke
2023-05-12 16:25:32 +02:00
8 changed files with 32 additions and 23 deletions

View File

@@ -49,7 +49,7 @@ Your imagination is the limit!
<a href="https://pypistats.org/packages/dev-gpt" target="_blank"> <a href="https://pypistats.org/packages/dev-gpt" target="_blank">
<img src="https://img.shields.io/pypi/dm/dev-gpt?color=%2334D058&label=pypi%20downloads" alt="Downloads"> <img src="https://img.shields.io/pypi/dm/dev-gpt?color=%2334D058&label=pypi%20downloads" alt="Downloads">
</a> </a>
<a href="https://discord.gg/ESn8ED6Fyn" target="_blank"> <a href="https://discord.gg/tBrFhx384D" target="_blank">
<img src="https://img.shields.io/badge/chat_on-Discord-7289DA?logo=discord&logoColor=white" alt="Discord Chat"> <img src="https://img.shields.io/badge/chat_on-Discord-7289DA?logo=discord&logoColor=white" alt="Discord Chat">
</a> </a>

View File

@@ -1,3 +1,3 @@
__version__ = '0.18.38' __version__ = '0.18.41'
from dev_gpt.cli import main from dev_gpt.cli import main

View File

@@ -77,7 +77,7 @@ class GPTSession:
}] }]
) )
break break
except RateLimitError: except (RateLimitError, openai.error.APIError):
sleep(1) sleep(1)
continue continue
return True return True
@@ -88,11 +88,12 @@ class GPTSession:
self.chars_prompt_so_far += chars_prompt self.chars_prompt_so_far += chars_prompt
self.chars_generation_so_far += chars_generation self.chars_generation_so_far += chars_generation
if print_costs: if print_costs:
print('\n') if os.environ['VERBOSE'].lower() == 'true':
money_prompt = self._calculate_money_spent(self.chars_prompt_so_far, self.pricing_prompt) print('\n')
money_generation = self._calculate_money_spent(self.chars_generation_so_far, self.pricing_generation) money_prompt = self._calculate_money_spent(self.chars_prompt_so_far, self.pricing_prompt)
print('Total money spent so far on openai.com:', f'${money_prompt + money_generation:.3f}') money_generation = self._calculate_money_spent(self.chars_generation_so_far, self.pricing_generation)
print('\n') print('Total money spent so far on openai.com:', f'${money_prompt + money_generation:.3f}')
print('\n')
@staticmethod @staticmethod
def _calculate_money_spent(num_chars, price): def _calculate_money_spent(num_chars, price):

View File

@@ -35,9 +35,6 @@ def path_param(func):
def wrapper(*args, **kwargs): def wrapper(*args, **kwargs):
path = os.path.expanduser(kwargs['path']) path = os.path.expanduser(kwargs['path'])
path = os.path.abspath(path) path = os.path.abspath(path)
if os.path.exists(path) and os.listdir(path):
click.echo(f"Error: The path {path} you provided via --path is not empty. Please choose a directory that does not exist or is empty.")
exit(1)
kwargs['path'] = path kwargs['path'] = path
return func(*args, **kwargs) return func(*args, **kwargs)
return wrapper return wrapper

View File

@@ -63,7 +63,7 @@ Description of the microservice:
condition_question='Does the microservice send requests to an API?', condition_question='Does the microservice send requests to an API?',
question_gen='Generate a question that asks for the endpoint and an example of a request and response when interacting with the external API.', question_gen='Generate a question that asks for the endpoint and an example of a request and response when interacting with the external API.',
extension_name='Example of API usage', extension_name='Example of API usage',
post_transformation_fn=translation(from_format='api instruction', to_format='python code snippet') post_transformation_fn=translation(from_format='api instruction', to_format='python code snippet raw without formatting')
) )
return microservice_description, test_description return microservice_description, test_description

View File

@@ -11,5 +11,5 @@ class DevGPTExecutor(Executor):
@jina_requests() @jina_requests()
def endpoint(self, docs: DocumentArray, **kwargs) -> DocumentArray: def endpoint(self, docs: DocumentArray, **kwargs) -> DocumentArray:
for d in docs: for d in docs:
d.text = json.dumps(func(json.loads(d.text))) d.text = func(d.text)
return docs return docs

View File

@@ -105,14 +105,18 @@ generated_string = gpt(prompt) # fill-in the prompt (str); the output is a stri
template_generate_function = PromptTemplate.from_template( template_generate_function = PromptTemplate.from_template(
general_guidelines_string + ''' general_guidelines_string + '''
Write a python function which receives as input a dictionary and outputs a dictionary. The function is called 'func'. Write a python function which receives as \
The function must full-fill: '{microservice_description}'. input json string (that can be parsed with the python function json.loads) and \
outputs a json string (that can be parsed with the python function json.loads). \
The function is called 'func'.
The function must fulfill the following description: '{microservice_description}'.
It will be tested with the following scenario: '{test_description}'. It will be tested with the following scenario: '{test_description}'.
For the implementation use the following package(s): '{packages}'. For the implementation use the following package(s): '{packages}'.
The code must start with the following import: The code must start with the following imports:
``` ```
from .apis import GPT_3_5_Turbo from .apis import GPT_3_5_Turbo
import json
``` ```
Obey the following rules: Obey the following rules:
''' + not_allowed_function_string + ''' ''' + not_allowed_function_string + '''
@@ -134,9 +138,10 @@ template_generate_test = PromptTemplate.from_template(
Write a single pytest case that tests the following scenario: '{test_description}'. In case the test scenario is not precise enough, test a general case without any assumptions. Write a single pytest case that tests the following scenario: '{test_description}'. In case the test scenario is not precise enough, test a general case without any assumptions.
Start the test with an extensive comment about the test case. If gpt_3_5_turbo is used in the executor, then the test must not check the exact output of the executor as it is not deterministic. Start the test with an extensive comment about the test case. If gpt_3_5_turbo is used in the executor, then the test must not check the exact output of the executor as it is not deterministic.
The test must start with the following import: The test must start with the following imports:
``` ```
from .microservice import func from .microservice import func
import json
``` ```
''' + not_allowed_function_string + ''' ''' + not_allowed_function_string + '''
The test must not open local files. The test must not open local files.
@@ -148,9 +153,9 @@ The test must not set any environment variables which require a key.
template_generate_requirements = PromptTemplate.from_template( template_generate_requirements = PromptTemplate.from_template(
general_guidelines_string + ''' general_guidelines_string + f'''
{code_files_wrapped} {{code_files_wrapped}}
Write the content of the requirements.txt file like this: Write the content of the requirements.txt file like this:
**requirements.txt** **requirements.txt**
@@ -160,9 +165,11 @@ Write the content of the requirements.txt file like this:
Add any more packages that are needed to run the code. Add any more packages that are needed to run the code.
You must not add gpt_3_5_turbo to the requirements.txt file. You must not add gpt_3_5_turbo to the requirements.txt file.
All versions are fixed using ~=, ==, <, >, <=, >=. The package versions must not have conflicts. Output only the requirements.txt file. All versions are fixed using ~=, ==, <, >, <=, >=. The package versions must not have conflicts.
''' + '\n' + template_code_wrapping_string
) {template_code_wrapping_string}
Note: you must only output the requirements.txt file - no other file.
''')
template_generate_apt_get_install = PromptTemplate.from_template( template_generate_apt_get_install = PromptTemplate.from_template(
@@ -399,7 +406,10 @@ Example:
**implementation.py** **implementation.py**
```python ```python
print('hello world') import json
def func(json_input: str) -> str:
return json_input['img_base64']
```''' ```'''
) )

View File

@@ -1,6 +1,7 @@
jina==3.15.1.dev14 jina==3.15.1.dev14
click click
streamlit==1.9.0 streamlit==1.9.0
altair==4.2.2
openai>=0.27.5 openai>=0.27.5
psutil psutil
jcloud jcloud