File size: 1,155 Bytes
da88570
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b5d96fe
da88570
 
b5d96fe
da88570
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import psutil
from huggingface_hub import InferenceClient
import json
import streamlit as st
import os
from dotenv import load_dotenv


class QwenLlmHandler:

    def __init__(self):
        load_dotenv()
        self.client = InferenceClient(
            "Qwen/Qwen2.5-Coder-32B-Instruct",
            token=os.getenv("INFERENCE_API_TOKEN"),
        )
        st.info("Using LLM Qwen/Qwen2.5-Coder-32B-Instruct via inference API")

    def extract_data(self, text: str, entities: str):
        messages = [{
            "role": "user",
            "content": """Du bist ein NER-Model. Gebe die Veranstaltungsinformationen aus dem text in JSON Format zurück.
                            Es sollen keine Markdown Elemente enthalten sein, nur das JSON Objekt als string. 
                            Gebe Nur das JSON als Antwort zurück. JSON_Schema:  
                            {""" +
                       entities +
                       """"
                       }
                       Text: """ + text}]

        response = self.client.chat_completion(messages, max_tokens=1000)
        return json.loads(response.choices[0].message.content)