Skip to content

Commit

Permalink
Merge pull request #781 from PrefectHQ/model-params
Browse files Browse the repository at this point in the history
Add docs on model parameters
  • Loading branch information
jlowin authored Jan 17, 2024
2 parents e0c1af0 + 9b83aab commit 851abc6
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 7 deletions.
12 changes: 11 additions & 1 deletion docs/docs/audio/speech.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,21 @@ ai_say('hello')
Your browser does not support the audio element.
</audio>

## Choosing a voice

Both `speak` and `@speech` accept a `voice` parameter that allows you to choose from a variety of voices. You can preview the available voices [here](https://platform.openai.com/docs/guides/text-to-speech/voice-options).

```python

## Saving audio files

The result of the `speak` function and `@speech` decorator is an audio stream. You can save this stream to disk like this:

```python
audio = marvin.speak("Hello, world!")
audio.stream_to_file("hello_world.mp3")
```
```


## Model parameters
You can pass parameters to the underlying API via the `model_kwargs` arguments of `speak` and `@speech`. These parameters are passed directly to the respective APIs, so you can use any supported parameter.
3 changes: 3 additions & 0 deletions docs/docs/text/classification.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ assert issue == IssueType.BUG

While convenient for certain scenarios, it's recommended to use the `classify` function for its greater flexibility and broader application range.

## Model parameters
You can pass parameters to the underlying API via the `model_kwargs` argument of `classify` or `@classifier`. These parameters are passed directly to the API, so you can use any supported parameter.

## Best practices

1. **Choosing the right labels**: Opt for labels that are mutually exclusive and collectively exhaustive for your classification context. This ensures clarity and prevents overlaps in categorization.
Expand Down
3 changes: 3 additions & 0 deletions docs/docs/text/extraction.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,6 @@ marvin.cast('Mass.', to=str, instruction="The state's abbreviation")
# MA
```


## Model parameters
You can pass parameters to the underlying API via the `model_kwargs` argument of `extract`. These parameters are passed directly to the API, so you can use any supported parameter.
6 changes: 5 additions & 1 deletion docs/docs/text/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -290,4 +290,8 @@ summarize_url('https://www.askmarvin.ai')
```

## Running a function
Running a function is quite simple: just call it like you would any other function! The LLM will generate the output based on the function's definition and the provided inputs. Remember that no source code is generated or executed, so every call to the function will be handled by the LLM. You can use caching or other techniques to improve performance if necessary.
Running a function is quite simple: just call it like you would any other function! The LLM will generate the output based on the function's definition and the provided inputs. Remember that no source code is generated or executed, so every call to the function will be handled by the LLM. You can use caching or other techniques to improve performance if necessary.


## Model parameters
You can pass parameters to the underlying API via the `model_kwargs` argument of `@fn`. These parameters are passed directly to the API, so you can use any supported parameter.
6 changes: 5 additions & 1 deletion docs/docs/text/generation.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ Data generation relies even more on instructions than other Marvin tools, as the

Instructions are freeform natural language and can be as general or specific as you like. The LLM will do its best to comply with any instructions you give.


## Model parameters
You can pass parameters to the underlying API via the `model_kwargs` argument of `generate`. These parameters are passed directly to the API, so you can use any supported parameter.

## Caching

Normally, each `generate` call would be independent. For some prompts, this would mean that each call produced very similar results to other calls. That would mean that generating, say, 10 items in a single call would produce a much more varied and high-quality result than generating 10 items in 5 calls of 2 items each.
Expand Down Expand Up @@ -207,4 +211,4 @@ The first and second tabs both show high-quality, varied results. The third tab
'Los Angeles',
'Houston'
]
```
```
5 changes: 4 additions & 1 deletion docs/docs/text/transformation.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,7 @@ class Location(marvin.Model):

Location('CHI')
# Location(city="Chicago", state="IL")
```
```

## Model parameters
You can pass parameters to the underlying API via the `model_kwargs` argument of `cast` or `@model`. These parameters are passed directly to the API, so you can use any supported parameter.
5 changes: 5 additions & 0 deletions docs/docs/vision/captioning.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,8 @@ Marvin can use OpenAI's vision API to process images as inputs.
</p>
</div>




## Model parameters
You can pass parameters to the underlying API via the `model_kwargs` argument of `caption`. These parameters are passed directly to the API, so you can use any supported parameter.
6 changes: 6 additions & 0 deletions docs/docs/vision/classification.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,9 @@ The `marvin.beta.classify` function is an enhanced version of `marvin.classify`
assert animal == 'dog'
assert dry_or_wet == 'wet'
```




## Model parameters
You can pass parameters to the underlying API via the `model_kwargs` and `vision_model_kwargs` arguments of `classify`. These parameters are passed directly to the respective APIs, so you can use any supported parameter.
3 changes: 3 additions & 0 deletions docs/docs/vision/extraction.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,6 @@ The `marvin.beta.extract` function is an enhanced version of `marvin.extract` th
```python
result == ["Pembroke Welsh Corgi", "Yorkshire Terrier"]
```

## Model parameters
You can pass parameters to the underlying API via the `model_kwargs` and `vision_model_kwargs` arguments of `extract`. These parameters are passed directly to the respective APIs, so you can use any supported parameter.
3 changes: 3 additions & 0 deletions docs/docs/vision/transformation.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,6 @@ If the target type isn't self-documenting, or you want to provide additional gui
```python
assert missing_items == ["eggs", "oranges"]
```

## Model parameters
You can pass parameters to the underlying API via the `model_kwargs` and `vision_model_kwargs` arguments of `cast`. These parameters are passed directly to the respective APIs, so you can use any supported parameter.
11 changes: 8 additions & 3 deletions src/marvin/ai/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,12 @@ def speak(
return response


def speech(fn: Optional[Callable] = None, *, voice: Optional[str] = None) -> Callable:
def speech(
fn: Optional[Callable] = None,
*,
voice: Optional[str] = None,
model_kwargs: Optional[dict] = None,
) -> Callable:
"""
Function decorator that generates audio from the wrapped function's return
value. The voice used for the audio can be specified.
Expand All @@ -93,11 +98,11 @@ def speech(fn: Optional[Callable] = None, *, voice: Optional[str] = None) -> Cal
Callable: The wrapped function.
"""
if fn is None:
return partial(speech, voice=voice)
return partial(speech, voice=voice, model_kwargs=model_kwargs)

@wraps(fn)
def wrapper(*args, **kwargs):
model = PythonFunction.from_function_call(fn, *args, **kwargs)
return speak(text=model.return_value, voice=voice)
return speak(text=model.return_value, voice=voice, model_kwargs=model_kwargs)

return wrapper

0 comments on commit 851abc6

Please sign in to comment.