Firsty1 commited on
Commit
5a1d02b
·
1 Parent(s): 4e11885

fix: use groq client directly for explain

Browse files
Files changed (2) hide show
  1. pipeline/explainer.py +4 -7
  2. requirements.txt +1 -0
pipeline/explainer.py CHANGED
@@ -1,5 +1,5 @@
1
  import os
2
- from huggingface_hub import InferenceClient
3
  from pathlib import Path
4
 
5
  BASE_DIR = Path(__file__).parent.parent
@@ -21,7 +21,7 @@ FALLACY_DEFINITIONS = {
21
  "intentional": "A deliberate and deceptive use of misleading reasoning"
22
  }
23
 
24
- DEFAULT_MODEL_ID = "HuggingFaceH4/zephyr-7b-beta"
25
 
26
 
27
  class FallacyExplainer:
@@ -30,16 +30,13 @@ class FallacyExplainer:
30
 
31
  def __init__(self, fallacy_classes=None, fallacy_definitions=None):
32
  self._model_id = os.environ.get("EXPLAIN_MODEL_ID", DEFAULT_MODEL_ID)
33
- self._client = InferenceClient(
34
- provider="groq",
35
- api_key=os.environ["GROQ_API_KEY"],
36
- )
37
  self.fallacy_classes = fallacy_classes or self.DEFAULT_FALLACY_CLASSES
38
  self.fallacy_definitions = fallacy_definitions or FALLACY_DEFINITIONS
39
  print(f"FallacyExplainer ready (model: {self._model_id} via Groq)")
40
 
41
  def _generate_with_prompt(self, prompt_text, max_new_tokens=128):
42
- result = self._client.chat_completion(
43
  model=self._model_id,
44
  messages=[{"role": "user", "content": prompt_text}],
45
  max_tokens=max_new_tokens,
 
1
  import os
2
+ from groq import Groq
3
  from pathlib import Path
4
 
5
  BASE_DIR = Path(__file__).parent.parent
 
21
  "intentional": "A deliberate and deceptive use of misleading reasoning"
22
  }
23
 
24
+ DEFAULT_MODEL_ID = "llama-3.1-8b-instant"
25
 
26
 
27
  class FallacyExplainer:
 
30
 
31
  def __init__(self, fallacy_classes=None, fallacy_definitions=None):
32
  self._model_id = os.environ.get("EXPLAIN_MODEL_ID", DEFAULT_MODEL_ID)
33
+ self._client = Groq(api_key=os.environ["GROQ_API_KEY"])
 
 
 
34
  self.fallacy_classes = fallacy_classes or self.DEFAULT_FALLACY_CLASSES
35
  self.fallacy_definitions = fallacy_definitions or FALLACY_DEFINITIONS
36
  print(f"FallacyExplainer ready (model: {self._model_id} via Groq)")
37
 
38
  def _generate_with_prompt(self, prompt_text, max_new_tokens=128):
39
+ result = self._client.chat.completions.create(
40
  model=self._model_id,
41
  messages=[{"role": "user", "content": prompt_text}],
42
  max_tokens=max_new_tokens,
requirements.txt CHANGED
@@ -7,3 +7,4 @@ pydantic==2.12.5
7
  accelerate==1.13.0
8
  safetensors==0.7.0
9
  huggingface_hub>=0.25.0
 
 
7
  accelerate==1.13.0
8
  safetensors==0.7.0
9
  huggingface_hub>=0.25.0
10
+ groq