Skip to content

Commit

Permalink
Merge pull request #239 from SylphAI-Inc/main
Browse files Browse the repository at this point in the history
V0.2.4 Release
  • Loading branch information
Sylph-AI authored Oct 27, 2024
2 parents 794319d + ff05211 commit ac39baf
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 21 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,16 @@
<a href="https://adalflow.sylph.ai/use_cases/question_answering.html">Trainer & Optimizers</a>
<p>
</h4>

<p align="center">
<a href="https://pypi.org/project/adalflow/">
<img alt="PyPI Version" src="https://img.shields.io/pypi/v/adalflow?style=flat-square">
</a>
<a href="https://pypi.org/project/adalflow/">
<img alt="PyPI Downloads" src="https://static.pepy.tech/badge/adalflow">
</a>
<a href="https://pypi.org/project/adalflow/">
<img alt="PyPI Downloads" src="https://static.pepy.tech/badge/adalflow/month">
</a>
<a href="https://star-history.com/#SylphAI-Inc/AdalFlow">
<img alt="GitHub stars" src="https://img.shields.io/github/stars/SylphAI-Inc/AdalFlow?style=flat-square">
</a>
Expand Down Expand Up @@ -217,7 +222,7 @@ AdalFlow full documentation available at [adalflow.sylph.ai](https://adalflow.sy
# AdalFlow: A Tribute to Ada Lovelace


AdalFlow is named in honor of [Ada Lovelace](https://en.wikipedia.org/wiki/Ada_Lovelace), the pioneering female mathematician who first recognized that machines could do more than just perform calculations. As a female-led team, we aim to inspire more women to enter the AI field.
AdalFlow is named in honor of [Ada Lovelace](https://en.wikipedia.org/wiki/Ada_Lovelace), the pioneering female mathematician who first recognized that machines could go beyond mere calculations. As a team led by a female founder, we aim to inspire more women to pursue careers in AI.


# Contributors
Expand Down
10 changes: 10 additions & 0 deletions adalflow/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
## [0.2.4] - 2024-10-27

### Added
- `BedrockAPIClient` to support the AWS Bedrock API. Note: still need more testing and documentation.

### Fixed
- `Generator` cache path: fixed the issue with invalid window path with incompaticle special characters: https://github.com/SylphAI-Inc/AdalFlow/issues/237
- Wrong score in the diagnose file as `prepare_eval` is not passing classification label 0 to the `eval_input`.


## [0.2.3] - 2024-09-20

### Rename
Expand Down
19 changes: 13 additions & 6 deletions adalflow/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,20 @@
<a href="https://pypi.org/project/adalflow/">
<img alt="PyPI Version" src="https://img.shields.io/pypi/v/adalflow?style=flat-square">
</a>
<a href="https://star-history.com/#SylphAI-Inc/LightRAG">
<img alt="GitHub stars" src="https://img.shields.io/github/stars/SylphAI-Inc/LightRAG?style=flat-square">
<a href="https://pypi.org/project/adalflow/">
<img alt="PyPI Downloads" src="https://static.pepy.tech/badge/adalflow">
</a>
<a href="https://pypi.org/project/adalflow/">
<img alt="PyPI Downloads" src="https://static.pepy.tech/badge/adalflow/month">
</a>
<a href="https://github.com/SylphAI-Inc/LightRAG/issues">
<img alt="Open Issues" src="https://img.shields.io/github/issues-raw/SylphAI-Inc/LightRAG?style=flat-square">
<a href="https://star-history.com/#SylphAI-Inc/AdalFlow">
<img alt="GitHub stars" src="https://img.shields.io/github/stars/SylphAI-Inc/AdalFlow?style=flat-square">
</a>
<a href="https://github.com/SylphAI-Inc/AdalFlow/issues">
<img alt="Open Issues" src="https://img.shields.io/github/issues-raw/SylphAI-Inc/AdalFlow?style=flat-square">
</a>
<a href="https://opensource.org/license/MIT">
<img alt="License" src="https://img.shields.io/github/license/SylphAI-Inc/LightRAG">
<img alt="License" src="https://img.shields.io/github/license/SylphAI-Inc/AdalFlow">
</a>
<a href="https://discord.gg/ezzszrRZvT">
<img alt="discord-invite" src="https://dcbadge.vercel.app/api/server/ezzszrRZvT?style=flat">
Expand Down Expand Up @@ -304,7 +310,8 @@ AdalFlow full documentation available at [adalflow.sylph.ai](https://adalflow.sy

# AdalFlow: A Tribute to Ada Lovelace

AdalFlow is named in honor of [Ada Lovelace](https://en.wikipedia.org/wiki/Ada_Lovelace), the pioneering female mathematician who first recognized that machines could do more than just calculations. As a female-led team, we aim to inspire more women to enter the AI field.

AdalFlow is named in honor of [Ada Lovelace](https://en.wikipedia.org/wiki/Ada_Lovelace), the pioneering female mathematician who first recognized that machines could go beyond mere calculations. As a team led by a female founder, we aim to inspire more women to pursue careers in AI.

# Contributors

Expand Down
2 changes: 1 addition & 1 deletion adalflow/adalflow/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "0.2.3"
__version__ = "0.2.4"

from adalflow.core.component import Component, fun_to_component
from adalflow.core.container import Sequential
Expand Down
35 changes: 26 additions & 9 deletions adalflow/adalflow/core/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
It is a pipeline that consists of three subcomponents."""

import os
import json
import re
from pathlib import Path

from typing import Any, Dict, Optional, Union, Callable, Tuple, List
import logging
Expand Down Expand Up @@ -114,16 +115,14 @@ def __init__(

template = template or DEFAULT_LIGHTRAG_SYSTEM_PROMPT

# Cache
model_str = (
f"{model_client.__class__.__name__}_{model_kwargs.get('model', 'default')}"
)
_cache_path = (
get_adalflow_default_root_path() if cache_path is None else cache_path
# create the cache path and initialize the cache engine

self.set_cache_path(
cache_path, model_client, model_kwargs.get("model", "default")
)
self.cache_path = os.path.join(_cache_path, f"cache_{model_str}.db")

CachedEngine.__init__(self, cache_path=self.cache_path)

Component.__init__(self)
GradComponent.__init__(self)
CallbackManager.__init__(self)
Expand All @@ -148,7 +147,6 @@ def __init__(
self.mock_output_data: str = "mock data"
self.data_map_func: Callable = None
self.set_data_map_func()
self.model_str = model_str
self._use_cache = use_cache

self._kwargs = {
Expand All @@ -163,6 +161,25 @@ def __init__(
}
self._teacher: Optional["Generator"] = None

def set_cache_path(self, cache_path: str, model_client: object, model: str):
"""Set the cache path for the generator."""

# Construct a valid model string using the client class name and model
self.model_str = f"{model_client.__class__.__name__}_{model}"

# Remove any characters that are not allowed in file names (cross-platform)
# On Windows, characters like `:<>?/\|*` are prohibited.
self.model_str = re.sub(r"[^a-zA-Z0-9_\-]", "_", self.model_str)

_cache_path = (
get_adalflow_default_root_path() if cache_path is None else cache_path
)

# Use pathlib to handle paths more safely across OS
self.cache_path = Path(_cache_path) / f"cache_{self.model_str}.db"

log.debug(f"Cache path set to: {self.cache_path}")

def get_cache_path(self) -> str:
r"""Get the cache path for the generator."""
return self.cache_path
Expand Down
8 changes: 6 additions & 2 deletions adalflow/adalflow/utils/cache.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import hashlib
import diskcache as dc
from pathlib import Path
from typing import Union


def hash_text(text: str):
Expand All @@ -15,9 +17,11 @@ def direct(text: str):


class CachedEngine:
def __init__(self, cache_path: str):
def __init__(self, cache_path: Union[str, Path]):
super().__init__()
self.cache_path = cache_path
self.cache_path = Path(cache_path)
self.cache_path.parent.mkdir(parents=True, exist_ok=True)

self.cache = dc.Cache(cache_path)

def _check_cache(self, prompt: str):
Expand Down
2 changes: 1 addition & 1 deletion adalflow/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[tool.poetry]
name = "adalflow"

version = "0.2.3"
version = "0.2.4"
description = "The Library to Build and Auto-optimize Any LLM Task Pipeline"
authors = ["Li Yin <[email protected]>"]
readme = "README.md"
Expand Down
27 changes: 27 additions & 0 deletions adalflow/tests/test_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import unittest
import os
import shutil
from pathlib import Path

from openai.types import CompletionUsage
from openai.types.chat import ChatCompletion
Expand Down Expand Up @@ -55,6 +56,32 @@ def test_generator_call(self):
print(f"output: {output}")
# self.assertEqual(output.data, "Generated text response")

def test_cache_path(self):
prompt_kwargs = {"input_str": "Hello, world!"}
model_kwargs = {"model": "phi3.5:latest"}

self.test_generator = Generator(
model_client=self.mock_api_client,
prompt_kwargs=prompt_kwargs,
model_kwargs=model_kwargs,
use_cache=True,
)

# Convert the path to a string to avoid the TypeError
cache_path = self.test_generator.get_cache_path()
cache_path_str = str(cache_path)

print(f"cache path: {cache_path}")

# Check if the sanitized model string is in the cache path
self.assertIn("phi3_5_latest", cache_path_str)

# Check if the cache path exists as a file (or directory, depending on your use case)

self.assertTrue(
Path(cache_path).exists(), f"Cache path {cache_path_str} does not exist"
)

def test_generator_prompt_logger_first_record(self):
# prompt_kwargs = {"input_str": "Hello, world!"}
# model_kwargs = {"model": "gpt-3.5-turbo"}
Expand Down

0 comments on commit ac39baf

Please sign in to comment.