Enrique Sanchez commited on
Commit
0624de9
1 Parent(s): 08d18d2

use llama2 for testing the model

Browse files
.github/workflows/main.yml CHANGED
@@ -5,40 +5,48 @@ name: Python application
5
 
6
  on:
7
  push:
8
- branches: [ "main" ]
9
  pull_request:
10
- branches: [ "main" ]
11
 
12
  permissions:
13
  contents: read
14
 
15
  jobs:
16
  build:
17
-
18
  runs-on: ubuntu-latest
19
 
20
  steps:
21
- - name: Install Ollama
22
- run: |
23
- apt-get update && apt-get install -y git build-essential curl
24
- curl https://ollama.ai/install.sh | sh
25
- ollama serve&
26
- ollama pull mistral
27
- - uses: actions/checkout@v4
28
- - name: Set up Python 3.10
29
- uses: actions/setup-python@v3
30
- with:
31
- python-version: "3.10"
32
- - name: Install Poetry
33
- run: |
34
- curl -sSL https://install.python-poetry.org | python3 -
35
- echo "$HOME/.local/bin" >> $GITHUB_PATH
36
- - name: Install dependencies with Poetry
37
- run: |
38
- poetry install
39
- - name: Lint with ruff
40
- run: |
41
- poetry run ruff check
42
- - name: Test with pytest
43
- run: |
44
- poetry run pytest --reruns 1 --reruns-delay 1
 
 
 
 
 
 
 
 
 
 
5
 
6
  on:
7
  push:
8
+ branches: ["main"]
9
  pull_request:
10
+ branches: ["main"]
11
 
12
  permissions:
13
  contents: read
14
 
15
  jobs:
16
  build:
 
17
  runs-on: ubuntu-latest
18
 
19
  steps:
20
+ - name: Install Ollama
21
+ run: |
22
+ apt-get update && apt-get install -y git build-essential curl
23
+ curl https://ollama.ai/install.sh | sh
24
+ ollama serve&
25
+ ollama pull mistral
26
+ ollama pull llama2
27
+ - uses: actions/checkout@v4
28
+ - name: Set up Python 3.10
29
+ uses: actions/setup-python@v3
30
+ with:
31
+ python-version: "3.10"
32
+ - name: Install Poetry
33
+ run: |
34
+ curl -sSL https://install.python-poetry.org | python3 -
35
+ echo "$HOME/.local/bin" >> $GITHUB_PATH
36
+ - name: Install dependencies with Poetry
37
+ run: |
38
+ poetry install
39
+ lint:
40
+ needs: build
41
+ runs-on: ubuntu-latest
42
+ steps:
43
+ - name: Lint with ruff
44
+ run: |
45
+ poetry run ruff check
46
+ test:
47
+ needs: lint
48
+ runs-on: ubuntu-latest
49
+ steps:
50
+ - name: Test with pytest
51
+ run: |
52
+ poetry run pytest --reruns 1 --reruns-delay 1
src/generate_conversation.py CHANGED
@@ -12,12 +12,14 @@ from langchain_experimental.tabular_synthetic_data.prompts import (
12
 
13
  examples = [
14
  {
15
- "example": """"Hola, como estas?", "Bien, y tu?, "Muy bien, gracias, y tu?", "Yo tambien muy bien, gracias", "Que bueno, nos vemos luego!", "Adios!"]"""
16
  }
17
  ]
18
 
19
 
20
- def generate_conversation(topic: str, sentiment: str = "positive") -> str:
 
 
21
  """Generate a conversation about a topic with a given sentiment.
22
 
23
  Args:
@@ -37,7 +39,7 @@ def generate_conversation(topic: str, sentiment: str = "positive") -> str:
37
  ),
38
  )
39
 
40
- model = Ollama(model="mistral")
41
 
42
  generator = SyntheticDataGenerator(template=template, llm=model)
43
  results = generator.generate(
 
12
 
13
  examples = [
14
  {
15
+ "example": """"Hello, how are you?", "Great! you?", "Good, good thanks", "Great! See you later!", "See you!"]"""
16
  }
17
  ]
18
 
19
 
20
+ def generate_conversation(
21
+ topic: str, sentiment: str = "positive", llm: str = "mistral"
22
+ ) -> str:
23
  """Generate a conversation about a topic with a given sentiment.
24
 
25
  Args:
 
39
  ),
40
  )
41
 
42
+ model = Ollama(model=llm)
43
 
44
  generator = SyntheticDataGenerator(template=template, llm=model)
45
  results = generator.generate(
src/summarization.py CHANGED
@@ -4,7 +4,7 @@ from langchain_community.document_loaders import TextLoader
4
  from langchain_community.llms import Ollama
5
 
6
 
7
- def topics_for_text(file_conv: str) -> str:
8
  """Get the topics for a text.
9
 
10
  Args:
@@ -18,7 +18,7 @@ def topics_for_text(file_conv: str) -> str:
18
  TOPICS:"""
19
 
20
  prompt = PromptTemplate.from_template(prompt_template)
21
- llm = Ollama(model="mistral")
22
 
23
  loader = TextLoader(file_conv)
24
  docs = loader.load()
 
4
  from langchain_community.llms import Ollama
5
 
6
 
7
+ def topics_for_text(file_conv: str, llm: str = "mistral") -> str:
8
  """Get the topics for a text.
9
 
10
  Args:
 
18
  TOPICS:"""
19
 
20
  prompt = PromptTemplate.from_template(prompt_template)
21
+ llm = Ollama(model=llm)
22
 
23
  loader = TextLoader(file_conv)
24
  docs = loader.load()
tests/test_sentiment.py CHANGED
@@ -44,7 +44,7 @@ def test_analyze_sentiment(sentiment):
44
  template="Generate a basic sentence with this sentiment: {sentiment}.",
45
  input_variables=["sentiment"],
46
  )
47
- model = Ollama(model="mistral")
48
  output_parser = StrOutputParser()
49
 
50
  chain = prompt | model | output_parser
 
44
  template="Generate a basic sentence with this sentiment: {sentiment}.",
45
  input_variables=["sentiment"],
46
  )
47
+ model = Ollama(model="llama2")
48
  output_parser = StrOutputParser()
49
 
50
  chain = prompt | model | output_parser
tests/{test_generate_conversation.py → test_sentiments_and_topics.py} RENAMED
@@ -1,18 +1,21 @@
1
  import os
2
  import tempfile
3
 
 
 
4
  from src.generate_conversation import generate_conversation
5
  from src.sentiment import analyze_sentiment
6
  from src.summarization import topics_for_text
7
 
 
 
8
 
9
- def test_generate_conversation_positive_sentiment():
10
- # Define the input parameters
11
- topic = "ai"
12
- sentiment = "admiration"
13
 
 
 
 
14
  # Call the function
15
- conversation = generate_conversation(topic, sentiment)
16
 
17
  new_sentiment = analyze_sentiment(conversation)
18
  # Assert that the conversation has a positive sentiment
@@ -28,5 +31,4 @@ def test_generate_conversation_positive_sentiment():
28
 
29
  new_topics = topics_for_text(temp_filepath)
30
  os.remove(temp_filepath)
31
-
32
- assert topic in new_topics, "Topic is not in the index of new_topics"
 
1
  import os
2
  import tempfile
3
 
4
+ import pytest
5
+
6
  from src.generate_conversation import generate_conversation
7
  from src.sentiment import analyze_sentiment
8
  from src.summarization import topics_for_text
9
 
10
+ SENTIMENTS = ["neutral", "sadness", "neutral", "joy"]
11
+ TOPICS = ["ai", "soccer", "art", "science"]
12
 
 
 
 
 
13
 
14
+ @pytest.mark.parametrize("sentiment", SENTIMENTS)
15
+ @pytest.mark.parametrize("topic", TOPICS)
16
+ def test_generate_conversation(sentiment, topic):
17
  # Call the function
18
+ conversation = generate_conversation(topic, sentiment, llm="llama2")
19
 
20
  new_sentiment = analyze_sentiment(conversation)
21
  # Assert that the conversation has a positive sentiment
 
31
 
32
  new_topics = topics_for_text(temp_filepath)
33
  os.remove(temp_filepath)
34
+ assert any(topic in word for word in new_topics)
 
tests/test_summarization.py DELETED
@@ -1,23 +0,0 @@
1
- import os
2
-
3
- from src.summarization import topics_for_text
4
-
5
-
6
- def test_topics_for_text():
7
- # Define the input parameters
8
-
9
- file_conv = os.path.abspath(
10
- os.path.join(
11
- os.path.dirname(__file__),
12
- "..",
13
- "conversations",
14
- "technology_1706560176_9889.txt",
15
- )
16
- )
17
-
18
- # Call the function
19
- topics = topics_for_text(file_conv)
20
-
21
- # Assert the expected output
22
- assert isinstance(topics, list)
23
- assert "technology" in topics