tanveeshsingh commited on
Commit
7572874
·
1 Parent(s): c692a42

Added llama

Browse files
Files changed (1) hide show
  1. app.py +15 -3
app.py CHANGED
@@ -1,13 +1,25 @@
1
  import gradio as gr
2
  from jinja2 import Template
3
  import openai
4
-
5
  API_ENDPOINT = "https://txl0ptjvttfogwt9.us-east-1.aws.endpoints.huggingface.cloud/v1/"
6
  API_KEY = "NA"
7
 
 
 
8
  def llama_guard_classify(conv_prefix, response):
9
- # Simulating LLaMA-Guard classification, replace with actual implementation
10
- return '{"output": 1}'
 
 
 
 
 
 
 
 
 
 
11
 
12
  def classify_prompt(conv_prefix, response):
13
  template_str = """
 
1
  import gradio as gr
2
  from jinja2 import Template
3
  import openai
4
+ import os
5
  API_ENDPOINT = "https://txl0ptjvttfogwt9.us-east-1.aws.endpoints.huggingface.cloud/v1/"
6
  API_KEY = "NA"
7
 
8
+ LLAMA_API_ENDPOINT=os.getenv("LLAMA_API_ENDPOINT")
9
+ LLAMA_API_KEY=os.getenv("LLAMA_API_KEY")
10
  def llama_guard_classify(conv_prefix, response):
11
+ model_name = 'meta-llama/Meta-Llama-Guard-3-8B'
12
+ client = openai.OpenAI(
13
+ base_url=LLAMA_API_ENDPOINT,
14
+ api_key=LLAMA_API_KEY
15
+ )
16
+ conv = conv_prefix
17
+ conv.append(response)
18
+ output = client.chat.completions.create(
19
+ model=model_name,
20
+ messages=conv,
21
+ )
22
+ return output.choices[0].message.content
23
 
24
  def classify_prompt(conv_prefix, response):
25
  template_str = """