-
Notifications
You must be signed in to change notification settings - Fork 0
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
Sourcery refactored main branch #1
base: main
Are you sure you want to change the base?
Conversation
|
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.
Function upload_file
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
|
||
if os.path.exists(file_path): | ||
data = parse_yaml(file_path) | ||
|
||
if raw: | ||
return {'prompt': data.get('prompt')} | ||
else: | ||
return FileResponse(file_path, media_type='application/x-yaml') | ||
|
||
else: | ||
|
||
if not os.path.exists(file_path): | ||
raise HTTPException(status_code=404, detail=f'File not found: {file_path}') | ||
data = parse_yaml(file_path) | ||
|
||
return ( | ||
{'prompt': data.get('prompt')} | ||
if raw | ||
else FileResponse(file_path, media_type='application/x-yaml') | ||
) |
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.
Function read_file_by_name
refactored with the following changes:
- Swap if/else branches (
swap-if-else-branches
) - Remove unnecessary else after guard condition (
remove-unnecessary-else
) - Replace if statement with if expression (
assign-if-exp
)
map_info = {} | ||
map_info = {'title': ask_for_input('title', 'str', True)} | ||
|
||
map_info['title'] = ask_for_input('title', 'str', True) | ||
map_info['uuid'] = str(uuid.uuid4()) | ||
map_info['description'] = ask_for_input('description', 'str', True) | ||
map_info['category'] = ask_for_input('category', 'str', True) | ||
map_info['provider'] = ask_for_input('provider', 'str', False) | ||
map_info['model'] = ask_for_input('model', 'str', False) | ||
|
||
# model settings with default values | ||
model_settings_fields = ['temperature', 'top_k', 'top_p', 'max_tokens', 'stream', 'presence_penalty', 'frequency_penalty'] | ||
model_settings_types = ['float', 'int', 'float', 'int', 'bool', 'float', 'float'] | ||
model_settings_defaults = [0.8, None, 1, None, False, 0.0, 0.0] | ||
|
||
model_settings = {field: ask_for_input(field, ftype, False, default) for field, ftype, default in zip(model_settings_fields, model_settings_types, model_settings_defaults)} | ||
|
||
# only add model_settings to map if it's not empty | ||
if any(model_settings.values()): | ||
map_info['model_settings'] = model_settings | ||
|
||
map_info['prompt'] = ask_for_input('prompt', 'str', True) | ||
|
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.
Function create_prompt
refactored with the following changes:
- Merge dictionary assignment with declaration (
merge-dict-assign
)
|
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.
Lines 219-269
refactored with the following changes:
- Replace f-string with no interpolated values with string [×2] (
remove-redundant-fstring
)
|
||
url = f'{self.base_url}/{repo_user}/{repo_name}/main/prompts/{full_prompt_name}.yml' | ||
full_prompt_name = full_prompt_name + '.yml' if not full_prompt_name.endswith('.yml') else full_prompt_name | ||
full_prompt_name = ( | ||
f'{full_prompt_name}.yml' | ||
if not full_prompt_name.endswith('.yml') | ||
else full_prompt_name | ||
) | ||
|
||
print(f'(status) retrieving template: {url}') | ||
|
||
try: | ||
response = requests.get(url) | ||
if response.status_code != 200: | ||
print(f'(error) error retrieving template - non 200 status code: {response.status_code}') | ||
return prompt_data | ||
|
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.
Function PromptLoader.get_template
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
Branch
main
refactored by Sourcery.If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.
See our documentation here.
Run Sourcery locally
Reduce the feedback loop during development by using the Sourcery editor plugin:
Review changes via command line
To manually merge these changes, make sure you're on the
main
branch, then run:Help us improve this pull request!