Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support vision models and function calling #8

Merged
merged 7 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,8 @@ iOSInjectionProject/
/Packages
.netrc
.idea
.swiftpm
.swiftpm

# Specific to this package

*.code-workspace
6 changes: 5 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
repos:
- repo: https://github.com/slessans/pre-commit-swift-format
rev: ""
rev: "fd627de92bdf84a75c924ed95691336d14e94cf1"
hooks:
- id: swift-format
args: ["--configuration", ".swift-format"]
- repo: https://github.com/kynan/nbstripout
rev: 0.8.1
hooks:
- id: nbstripout
5 changes: 4 additions & 1 deletion .swift-format
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,8 @@
"respectsExistingLineBreaks": true,
"lineBreakBeforeEachArgument": true,
"multiElementCollectionTrailingCommas": true,
"spacesAroundRangeFormationOperators": true
"spacesAroundRangeFormationOperators": true,
"rules": {
"AlwaysUseLowerCamelCase": false
}
}
14 changes: 14 additions & 0 deletions Package.resolved
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it necessary to commit this file?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure. It was created after I added swift-collections. Are lock files usually included for dependencies in Swift packages?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so, Xcode should resolve the dependencies when you compile. I'd suggest to remove.

It's also a bit unfortunate that another dependency had to be added, is it just to guarantee reproducibility for tests? If so, we should be able to move it to the test target (but we can do it later).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

swift-collections is necessary for the reproducibility of some tests, and is also needed in the library itself. I'm not sure how else you would test stringification of dictionaries if you don't have a deterministic key order.

I see that mlx-swift has a Package.resolved file, and Claude says it's usually included in Swift packages, for what it's worth.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"pins" : [
{
"identity" : "swift-collections",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-collections.git",
"state" : {
"revision" : "671108c96644956dddcd89dd59c203dcdb36cec7",
"version" : "1.1.4"
}
}
],
"version" : 2
}
10 changes: 9 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,25 @@ let package = Package(
targets: ["Jinja"]
)
],
dependencies: [
.package(url: "https://github.com/apple/swift-collections.git", from: "1.1.4")
],
targets: [
// Targets are the basic building blocks of a package, defining a module or a test suite.
// Targets can depend on other targets in this package and products from dependencies.
.target(
name: "Jinja",
dependencies: [
.product(name: "OrderedCollections", package: "swift-collections")
],
path: "Sources",
swiftSettings: [.enableUpcomingFeature("BareSlashRegexLiterals")]
),
.testTarget(
name: "JinjaTests",
dependencies: ["Jinja"],
dependencies: [
"Jinja"
],
path: "Tests",
swiftSettings: [.enableUpcomingFeature("BareSlashRegexLiterals")]
),
Expand Down
37 changes: 31 additions & 6 deletions Sources/Ast.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import Foundation
import OrderedCollections

protocol Statement {}

Expand Down Expand Up @@ -41,15 +42,15 @@ struct TupleLiteral: Literal {
}

struct ObjectLiteral: Literal {
var value: [(Expression, Expression)]
var value: OrderedDictionary<String, Expression>
}

struct Set: Statement {
var assignee: Expression
var value: Expression
}

struct If: Statement {
struct If: Statement, Expression {
var test: Expression
var body: [Statement]
var alternate: [Statement]
Expand All @@ -59,14 +60,14 @@ struct Identifier: Expression {
var value: String
}

protocol Loopvar {}
extension Identifier: Loopvar {}
extension TupleLiteral: Loopvar {}
typealias Loopvar = Expression

struct For: Statement {
var loopvar: Loopvar
var iterable: Expression
var body: [Statement]
var defaultBlock: [Statement]
var test: Expression?
}

struct MemberExpression: Expression {
Expand All @@ -92,7 +93,11 @@ extension CallExpression: Filter {}

struct FilterExpression: Expression {
var operand: Expression
var filter: Filter
var filter: Identifier
var args: [Expression]
var kwargs: [KeywordArgumentExpression]
var dyn_args: Expression?
var dyn_kwargs: Expression?
}

struct TestExpression: Expression {
Expand Down Expand Up @@ -124,3 +129,23 @@ struct KeywordArgumentExpression: Expression {
struct NullLiteral: Literal {
var value: Any? = nil
}

struct SelectExpression: Expression {
var iterable: Expression
var test: Expression
}

struct Macro: Statement {
var name: Identifier
var args: [Expression]
var body: [Statement]
}

struct KeywordArgumentsValue: RuntimeValue {
var value: [String: any RuntimeValue]
var builtins: [String: any RuntimeValue] = [:]

func bool() -> Bool {
!value.isEmpty
}
}
Loading