(self, question)
| 106 | return response |
| 107 | |
| 108 | def generate_query_llm(self, question): |
| 109 | prompt = f"""Given the following question, generate several keywords, using 'cosmos' as the separator. |
| 110 | |
| 111 | Question: {question} |
| 112 | |
| 113 | Format your response as a JSON object with a "keywords" field containing the selected text. |
| 114 | |
| 115 | Example response format: |
| 116 | {{"keywords": "keyword1, keyword2, keyword3"}}""" |
| 117 | |
| 118 | # Get LLM response |
| 119 | response = self.retriever_llm.llm.get_completion(prompt,response_format={"type": "json_schema", "json_schema": { |
| 120 | "name": "response", |
| 121 | "schema": { |
| 122 | "type": "object", |
| 123 | "properties": { |
| 124 | "keywords": { |
| 125 | "type": "string", |
| 126 | } |
| 127 | }, |
| 128 | "required": ["keywords"], |
| 129 | "additionalProperties": False |
| 130 | }, |
| 131 | "strict": True |
| 132 | }}) |
| 133 | print("response:{}".format(response)) |
| 134 | try: |
| 135 | response = json.loads(response)["keywords"] |
| 136 | except: |
| 137 | response = response.strip() |
| 138 | return response |
| 139 | |
| 140 | def answer_question(self, question: str, category: int, answer: str) -> str: |
| 141 | """Generate answer for a question given the conversation context.""" |
no test coverage detected