mirror of
https://github.com/aljazceru/dev-gpt.git
synced 2025-12-20 15:14:20 +01:00
20 lines
427 B
Python
20 lines
427 B
Python
import json
|
|
|
|
def make_prompt_friendly(text):
|
|
return text.replace('{', '{{').replace('}', '}}')
|
|
|
|
def context_to_string(context):
|
|
context_strings = []
|
|
for k, v in context.items():
|
|
if isinstance(v, dict):
|
|
v = json.dumps(v, indent=4)
|
|
v = make_prompt_friendly(v)
|
|
context_strings.append(f'''\
|
|
{k}:
|
|
```
|
|
{v}
|
|
```
|
|
'''
|
|
)
|
|
return '\n'.join(context_strings)
|