(self, msgs, max_retries=2)
| 82 | return response.strip() |
| 83 | |
| 84 | def call_server(self, msgs, max_retries=2): |
| 85 | client = OpenAI( |
| 86 | api_key=SUMMARY_API_KEY, |
| 87 | base_url=SUMMARY_URL, |
| 88 | ) |
| 89 | for attempt in range(max_retries): |
| 90 | try: |
| 91 | chat_response = client.chat.completions.create( |
| 92 | model=SUMMARY_MODEL_NAME, |
| 93 | messages=msgs, |
| 94 | temperature=0.7 |
| 95 | ) |
| 96 | content = chat_response.choices[0].message.content |
| 97 | print(content) |
| 98 | if content: |
| 99 | try: |
| 100 | json.loads(content) |
| 101 | except: |
| 102 | # extract json from string |
| 103 | left = content.find('{') |
| 104 | right = content.rfind('}') |
| 105 | if left != -1 and right != -1 and left <= right: |
| 106 | content = content[left:right+1] |
| 107 | return content |
| 108 | except Exception as e: |
| 109 | print(e) |
| 110 | if attempt == (max_retries - 1): |
| 111 | return "" |
| 112 | continue |
| 113 | |
| 114 | |
| 115 | def jina_readpage(self, url: str) -> str: |
nothing calls this directly
no outgoing calls
no test coverage detected